use of org.chromium.chrome.browser.init.EmptyBrowserParts 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);
}
}
use of org.chromium.chrome.browser.init.EmptyBrowserParts 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);
}
}
use of org.chromium.chrome.browser.init.EmptyBrowserParts 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:
notifyDownloadPending(entry.downloadGuid, entry.fileName, 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);
}
}
Aggregations