OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.chrome.browser; |
| 6 |
| 7 import android.Manifest; |
| 8 import android.content.pm.PackageManager; |
| 9 |
| 10 import org.chromium.base.annotations.SuppressFBWarnings; |
| 11 import org.chromium.base.library_loader.LibraryProcessType; |
| 12 import org.chromium.base.library_loader.ProcessInitException; |
| 13 import org.chromium.chrome.browser.externalauth.ExternalAuthUtils; |
| 14 import org.chromium.content.app.ContentApplication; |
| 15 import org.chromium.content.browser.BrowserStartupController; |
| 16 |
| 17 /** |
| 18 * App-specific version of ChromeBrowserProvider that deals with app-side initia
lization, |
| 19 * notifications and operations depending on the sync status. |
| 20 * |
| 21 * TODO(newt): merge with ChromeBrowserProvider after upstreaming. |
| 22 */ |
| 23 public class ChromeBrowserProviderStaging extends ChromeBrowserProvider { |
| 24 |
| 25 @Override |
| 26 public boolean onCreate() { |
| 27 ContentApplication.initCommandLine(getContext()); |
| 28 |
| 29 BrowserStartupController.get(getContext(), LibraryProcessType.PROCESS_BR
OWSER) |
| 30 .addStartupCompletedObserver( |
| 31 new BrowserStartupController.StartupCallback() { |
| 32 @Override |
| 33 public void onSuccess(boolean alreadyStarted) { |
| 34 ensureNativeChromeLoadedOnUIThread(); |
| 35 } |
| 36 |
| 37 @Override |
| 38 public void onFailure() { |
| 39 } |
| 40 }); |
| 41 |
| 42 return super.onCreate(); |
| 43 } |
| 44 |
| 45 @SuppressFBWarnings("DM_EXIT") |
| 46 @Override |
| 47 protected boolean ensureNativeChromeLoadedOnUIThread() { |
| 48 if (isNativeSideInitialized()) return true; |
| 49 // Only start the GoogleServicesManager if we were initialized via a cal
l to the browser |
| 50 // provider. If it wasn't, let the Chrome browser worry about sequencin
g the |
| 51 // initialization. |
| 52 boolean shouldStartGoogleServicesManager = mContentProviderApiCalled; |
| 53 try { |
| 54 ((ChromiumApplication) getContext().getApplicationContext()) |
| 55 .startChromeBrowserProcessesSync(shouldStartGoogleServicesMa
nager); |
| 56 } catch (ProcessInitException e) { |
| 57 // Chrome browser runs in the background, so exit silently; but do e
xit, since |
| 58 // otherwise the next attempt to use Chrome will find a broken JNI. |
| 59 System.exit(-1); |
| 60 } |
| 61 return super.ensureNativeChromeLoadedOnUIThread(); |
| 62 } |
| 63 |
| 64 @Override |
| 65 protected boolean hasReadAccess() { |
| 66 return hasPermission(Manifest.permission.READ_HISTORY_BOOKMARKS); |
| 67 } |
| 68 |
| 69 @Override |
| 70 protected boolean hasWriteAccess() { |
| 71 return hasPermission(Manifest.permission.WRITE_HISTORY_BOOKMARKS); |
| 72 } |
| 73 |
| 74 private boolean hasPermission(String permission) { |
| 75 boolean hasPermission = getContext().checkCallingOrSelfPermission(permis
sion) |
| 76 == PackageManager.PERMISSION_GRANTED; |
| 77 boolean isSystemOrGoogleCaller = ExternalAuthUtils.getInstance().isCalle
rValid( |
| 78 getContext(), ExternalAuthUtils.FLAG_SHOULD_BE_GOOGLE_SIGNED |
| 79 | ExternalAuthUtils.FLAG_SHOULD_BE_SYSTEM); |
| 80 return hasPermission || isSystemOrGoogleCaller; |
| 81 } |
| 82 } |
OLD | NEW |