Search in sources :

Example 1 with BrowserParts

use of org.chromium.chrome.browser.init.BrowserParts in project AndroidChromium by JackyAndroid.

the class ManageSpaceActivity method onCreate.

@SuppressLint("CommitPrefEdits")
@Override
protected void onCreate(Bundle savedInstanceState) {
    ensureActivityNotExported();
    setContentView(R.layout.manage_space_activity);
    Resources r = getResources();
    setTitle(String.format(r.getString(R.string.storage_management_activity_label), r.getString(R.string.app_name)));
    mSiteDataSizeText = (TextView) findViewById(R.id.site_data_storage_size_text);
    mSiteDataSizeText.setText(R.string.storage_management_computing_size);
    mUnimportantSiteDataSizeText = (TextView) findViewById(R.id.unimportant_site_data_storage_size_text);
    mUnimportantSiteDataSizeText.setText(R.string.storage_management_computing_size);
    mManageSiteDataButton = (Button) findViewById(R.id.manage_site_data_storage);
    mClearUnimportantButton = (Button) findViewById(R.id.clear_unimportant_site_data_storage);
    // We initially disable all of our buttons except for the 'Clear All Data' button, and wait
    // until the browser is finished initializing to enable them. We want to make sure the
    // 'Clear All Data' button is enabled so users can do this even if it's taking forever for
    // the Chromium process to boot up.
    mManageSiteDataButton.setEnabled(false);
    mClearUnimportantButton.setEnabled(false);
    mManageSiteDataButton.setOnClickListener(this);
    mClearUnimportantButton.setOnClickListener(this);
    // We should only be using this activity if we're >= KitKat.
    assert android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT;
    mClearAllDataButton = (Button) findViewById(R.id.clear_all_data);
    mClearAllDataButton.setOnClickListener(this);
    super.onCreate(savedInstanceState);
    BrowserParts parts = new EmptyBrowserParts() {

        @Override
        public void finishNativeInitialization() {
            ManageSpaceActivity.this.finishNativeInitialization();
        }

        @Override
        public void onStartupFailure() {
            mSiteDataSizeText.setText(R.string.storage_management_startup_failure);
            mUnimportantSiteDataSizeText.setText(R.string.storage_management_startup_failure);
        }
    };
    // Allow reading/writing to disk to check whether the last attempt was successful before
    // kicking off the browser process initialization.
    StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
    StrictMode.allowThreadDiskWrites();
    try {
        String productVersion = AboutChromePreferences.getApplicationVersion(this, ChromeVersionInfo.getProductVersion());
        String failedVersion = ContextUtils.getAppSharedPreferences().getString(PREF_FAILED_BUILD_VERSION, null);
        if (TextUtils.equals(failedVersion, productVersion)) {
            parts.onStartupFailure();
            return;
        }
        // If the native library crashes and kills the browser process, there is no guarantee
        // java-side the pref will be written before the process dies. We want to make sure we
        // don't attempt to start the browser process and have it kill chrome. This activity is
        // used to clear data for the chrome app, so it must be particularly error resistant.
        ContextUtils.getAppSharedPreferences().edit().putString(PREF_FAILED_BUILD_VERSION, productVersion).commit();
    } finally {
        StrictMode.setThreadPolicy(oldPolicy);
    }
    try {
        ChromeBrowserInitializer.getInstance(getApplicationContext()).handlePreNativeStartup(parts);
        ChromeBrowserInitializer.getInstance(getApplicationContext()).handlePostNativeStartup(true, parts);
    } catch (Exception e) {
        // We don't want to exit, as the user should still be able to clear all browsing data.
        Log.e(TAG, "Unable to load native library.", e);
        mSiteDataSizeText.setText(R.string.storage_management_startup_failure);
        mUnimportantSiteDataSizeText.setText(R.string.storage_management_startup_failure);
    }
}
Also used : StrictMode(android.os.StrictMode) EmptyBrowserParts(org.chromium.chrome.browser.init.EmptyBrowserParts) Resources(android.content.res.Resources) BrowserParts(org.chromium.chrome.browser.init.BrowserParts) EmptyBrowserParts(org.chromium.chrome.browser.init.EmptyBrowserParts) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) SuppressLint(android.annotation.SuppressLint)

Example 2 with BrowserParts

use of org.chromium.chrome.browser.init.BrowserParts in project AndroidChromium by JackyAndroid.

the class AccountsChangedReceiver method startBrowserIfNeededAndValidateAccounts.

@SuppressFBWarnings("DM_EXIT")
private static void startBrowserIfNeededAndValidateAccounts(final Context context) {
    BrowserParts parts = new EmptyBrowserParts() {

        @Override
        public void finishNativeInitialization() {
            ThreadUtils.runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    SigninHelper.get(context).validateAccountSettings(true);
                }
            });
        }

        @Override
        public void onStartupFailure() {
            // Startup failed. So notify SigninHelper of changed accounts via
            // shared prefs.
            SigninHelper.markAccountsChangedPref(context);
        }
    };
    try {
        ChromeBrowserInitializer.getInstance(context).handlePreNativeStartup(parts);
        ChromeBrowserInitializer.getInstance(context).handlePostNativeStartup(true, parts);
    } catch (ProcessInitException e) {
        Log.e(TAG, "Unable to load native library.", e);
        ChromeApplication.reportStartupErrorAndExit(e);
    }
}
Also used : EmptyBrowserParts(org.chromium.chrome.browser.init.EmptyBrowserParts) ProcessInitException(org.chromium.base.library_loader.ProcessInitException) BrowserParts(org.chromium.chrome.browser.init.BrowserParts) EmptyBrowserParts(org.chromium.chrome.browser.init.EmptyBrowserParts) SuppressFBWarnings(org.chromium.base.annotations.SuppressFBWarnings)

Example 3 with BrowserParts

use of org.chromium.chrome.browser.init.BrowserParts in project AndroidChromium by JackyAndroid.

the class DownloadNotificationService method handleDownloadOperation.

/**
     * Helper method to launch the browser process and handle a download operation that is included
     * in the given intent.
     * @param intent Intent with the download operation.
     */
private void handleDownloadOperation(final Intent intent) {
    final DownloadSharedPreferenceEntry entry = getDownloadEntryFromIntent(intent);
    if (intent.getAction() == ACTION_DOWNLOAD_PAUSE) {
        // nothing in that case.
        if (!DownloadManagerService.hasDownloadManagerService()) {
            notifyDownloadPaused(entry.downloadGuid, !entry.isOffTheRecord, false);
            return;
        }
    } else if (intent.getAction() == ACTION_DOWNLOAD_RESUME) {
        boolean metered = DownloadManagerService.isActiveNetworkMetered(mContext);
        if (!entry.canDownloadWhileMetered) {
            // If user manually resumes a download, update the network type if it
            // is not metered previously.
            entry.canDownloadWhileMetered = metered;
        }
        // Update the SharedPreference entry.
        addOrReplaceSharedPreferenceEntry(entry);
    } else if (intent.getAction() == ACTION_DOWNLOAD_RESUME_ALL && (mDownloadSharedPreferenceEntries.isEmpty() || DownloadManagerService.hasDownloadManagerService())) {
        return;
    } else if (intent.getAction() == ACTION_DOWNLOAD_OPEN) {
    // TODO(fgorski): Do we even need to do anything special here, before we launch Chrome?
    }
    BrowserParts parts = new EmptyBrowserParts() {

        @Override
        public boolean shouldStartGpuProcess() {
            return false;
        }

        @Override
        public void finishNativeInitialization() {
            int itemType = entry != null ? entry.itemType : (intent.getAction() == ACTION_DOWNLOAD_OPEN ? DownloadSharedPreferenceEntry.ITEM_TYPE_OFFLINE_PAGE : DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLOAD);
            DownloadServiceDelegate downloadServiceDelegate = intent.getAction() == ACTION_DOWNLOAD_OPEN ? null : getServiceDelegate(itemType);
            switch(intent.getAction()) {
                case ACTION_DOWNLOAD_CANCEL:
                    // TODO(qinmin): Alternatively, we can delete the downloaded content on
                    // SD card, and remove the download ID from the SharedPreferences so we
                    // don't need to restart the browser process. http://crbug.com/579643.
                    cancelNotification(entry.notificationId, entry.downloadGuid);
                    downloadServiceDelegate.cancelDownload(entry.downloadGuid, entry.isOffTheRecord, IntentUtils.safeGetBooleanExtra(intent, EXTRA_NOTIFICATION_DISMISSED, false));
                    break;
                case ACTION_DOWNLOAD_PAUSE:
                    downloadServiceDelegate.pauseDownload(entry.downloadGuid, entry.isOffTheRecord);
                    break;
                case ACTION_DOWNLOAD_RESUME:
                    notifyDownloadProgress(entry.downloadGuid, entry.fileName, INVALID_DOWNLOAD_PERCENTAGE, 0, 0, entry.isOffTheRecord, entry.canDownloadWhileMetered, entry.isOfflinePage());
                    downloadServiceDelegate.resumeDownload(entry.buildDownloadItem(), true);
                    break;
                case ACTION_DOWNLOAD_RESUME_ALL:
                    assert entry == null;
                    resumeAllPendingDownloads();
                    break;
                case ACTION_DOWNLOAD_OPEN:
                    OfflinePageDownloadBridge.openDownloadedPage(IntentUtils.safeGetStringExtra(intent, EXTRA_DOWNLOAD_GUID));
                    break;
                default:
                    Log.e(TAG, "Unrecognized intent action.", intent);
                    break;
            }
            if (intent.getAction() != ACTION_DOWNLOAD_OPEN) {
                downloadServiceDelegate.destroyServiceDelegate();
            }
        }
    };
    try {
        ChromeBrowserInitializer.getInstance(mContext).handlePreNativeStartup(parts);
        ChromeBrowserInitializer.getInstance(mContext).handlePostNativeStartup(true, parts);
    } catch (ProcessInitException e) {
        Log.e(TAG, "Unable to load native library.", e);
        ChromeApplication.reportStartupErrorAndExit(e);
    }
}
Also used : EmptyBrowserParts(org.chromium.chrome.browser.init.EmptyBrowserParts) ProcessInitException(org.chromium.base.library_loader.ProcessInitException) BrowserParts(org.chromium.chrome.browser.init.BrowserParts) EmptyBrowserParts(org.chromium.chrome.browser.init.EmptyBrowserParts) Paint(android.graphics.Paint)

Example 4 with BrowserParts

use of org.chromium.chrome.browser.init.BrowserParts in project AndroidChromium by JackyAndroid.

the class ChromeBrowserSyncAdapter method onPerformSync.

@Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {
    if (extras.getBoolean(ContentResolver.SYNC_EXTRAS_INITIALIZE)) {
        Account signedInAccount = ChromeSigninController.get(getContext()).getSignedInUser();
        if (account.equals(signedInAccount)) {
            ContentResolver.setIsSyncable(account, authority, 1);
        } else {
            ContentResolver.setIsSyncable(account, authority, 0);
        }
        return;
    }
    PendingInvalidation invalidation = new PendingInvalidation(extras);
    DelayedInvalidationsController controller = DelayedInvalidationsController.getInstance();
    if (!controller.shouldNotifyInvalidation(extras)) {
        controller.addPendingInvalidation(getContext(), account.name, invalidation);
        return;
    }
    // Browser startup is asynchronous, so we will need to wait for startup to finish.
    Semaphore semaphore = new Semaphore(0);
    // Configure the BrowserParts with all the data it needs.
    BrowserParts parts = getBrowserParts(mApplication, account.name, invalidation, syncResult, semaphore);
    startBrowserProcess(parts, syncResult, semaphore);
    try {
        // to trigger and asynchronous sync cycle, so 5 minutes is generous.
        if (!semaphore.tryAcquire(5, TimeUnit.MINUTES)) {
            Log.w(TAG, "Sync request timed out!");
            syncResult.stats.numIoExceptions++;
        }
    } catch (InterruptedException e) {
        Log.w(TAG, "Got InterruptedException when trying to request an invalidation.", e);
        // Using numIoExceptions so Android will treat this as a soft error.
        syncResult.stats.numIoExceptions++;
    }
}
Also used : Account(android.accounts.Account) Semaphore(java.util.concurrent.Semaphore) PendingInvalidation(org.chromium.components.invalidation.PendingInvalidation) BrowserParts(org.chromium.chrome.browser.init.BrowserParts) EmptyBrowserParts(org.chromium.chrome.browser.init.EmptyBrowserParts)

Aggregations

BrowserParts (org.chromium.chrome.browser.init.BrowserParts)4 EmptyBrowserParts (org.chromium.chrome.browser.init.EmptyBrowserParts)4 ProcessInitException (org.chromium.base.library_loader.ProcessInitException)2 Account (android.accounts.Account)1 SuppressLint (android.annotation.SuppressLint)1 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)1 Resources (android.content.res.Resources)1 Paint (android.graphics.Paint)1 StrictMode (android.os.StrictMode)1 Semaphore (java.util.concurrent.Semaphore)1 SuppressFBWarnings (org.chromium.base.annotations.SuppressFBWarnings)1 PendingInvalidation (org.chromium.components.invalidation.PendingInvalidation)1