org.chromium.chrome.browser.profiles.Profile Java Examples

The following examples show how to use org.chromium.chrome.browser.profiles.Profile. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProfileDataCache.java    From delion with Apache License 2.0 6 votes vote down vote up
public ProfileDataCache(Context context, Profile profile) {
    ProfileDownloader.addObserver(this);

    mContext = context;
    mProfile = profile;

    final DeviceDisplayInfo info = DeviceDisplayInfo.create(context);
    mImageSizePx = (int) Math.ceil(PROFILE_IMAGE_SIZE_DP * info.getDIPScale());
    mImageStrokePx = (int) Math.ceil(PROFILE_IMAGE_STROKE_DP * info.getDIPScale());
    mImageStrokeColor = Color.WHITE;

    Bitmap placeHolder = BitmapFactory.decodeResource(mContext.getResources(),
            R.drawable.fre_placeholder);
    mPlaceholderImage = getCroppedBitmap(placeHolder);

    update();
}
 
Example #2
Source File: AccountsChangedReceiver.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void onReceive(final Context context, Intent intent) {
    if (AccountManager.LOGIN_ACCOUNTS_CHANGED_ACTION.equals(intent.getAction())) {
        final Account signedInUser =
                ChromeSigninController.get(context).getSignedInUser();
        if (signedInUser != null) {
            BrowserStartupController.StartupCallback callback =
                    new BrowserStartupController.StartupCallback() {
                @Override
                public void onSuccess(boolean alreadyStarted) {
                    OAuth2TokenService.getForProfile(Profile.getLastUsedProfile())
                            .validateAccounts(context);
                }

                @Override
                public void onFailure() {
                    Log.w(TAG, "Failed to start browser process.");
                }
            };
            startBrowserProcessOnUiThread(context, callback);
        }
    }
}
 
Example #3
Source File: TranslatePreferences.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int itemId = item.getItemId();
    if (itemId == R.id.menu_id_targeted_help) {
        HelpAndFeedback.getInstance(getActivity())
                .show(getActivity(), getString(R.string.help_context_translate),
                        Profile.getLastUsedProfile(), null);
        return true;
    } else if (itemId == R.id.menu_id_reset) {
        PrefServiceBridge.getInstance().resetTranslateDefaults();
        Toast.makeText(getActivity(), getString(
                R.string.translate_prefs_toast_description),
                Toast.LENGTH_SHORT).show();
        return true;
    }
    return false;
}
 
Example #4
Source File: OffTheRecordTabModel.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Destroys the Incognito profile when all Incognito tabs have been closed.  Also resets the
 * delegate TabModel to be a stub EmptyTabModel.
 */
protected void destroyIncognitoIfNecessary() {
    ThreadUtils.assertOnUiThread();
    if (!isEmpty() || mDelegateModel instanceof EmptyTabModel || mIsAddingTab) {
        return;
    }

    Profile profile = getProfile();
    mDelegateModel.destroy();

    // Only delete the incognito profile if there are no incognito tabs open in any tab
    // model selector as the profile is shared between them.
    if (profile != null && !mDelegate.doOffTheRecordTabsExist()) {
        IncognitoNotificationManager.dismissIncognitoNotification();

        profile.destroyWhenAppropriate();
    }

    mDelegateModel = EmptyTabModel.getInstance();
}
 
Example #5
Source File: ContextualSearchSceneLayer.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private native void nativeUpdateContextualSearchLayer(long nativeContextualSearchSceneLayer,
int searchBarBackgroundResourceId, int searchContextResourceId,
int searchTermResourceId, int searchCaptionResourceId, int searchBarShadowResourceId,
int searchProviderIconResourceId, int quickActionIconResourceId, int arrowUpResourceId,
int closeIconResourceId, int progressBarBackgroundResourceId, int progressBarResourceId,
int searchPromoResourceId, int peekPromoRippleResourceId, int peekPromoTextResourceId,
float dpToPx, float basePageBrightness, float basePageYOffset, WebContents webContents,
boolean searchPromoVisible, float searchPromoHeight, float searchPromoOpacity,
boolean searchPeekPromoVisible, float searchPeekPromoHeight,
float searchPeekPromoPaddingPx, float searchPeekPromoRippleWidth,
float searchPeekPromoRippleOpacity, float searchPeekPromoTextOpacity,
float searchPanelX, float searchPanelY, float searchPanelWidth, float searchPanelHeight,
float searchBarMarginSide, float searchBarHeight, float searchContextOpacity,
float searchTextLayerMinHeight, float searchTermOpacity, float searchTermCaptionSpacing,
float searchCaptionAnimationPercentage, boolean searchCaptionVisible,
boolean searchBarBorderVisible, float searchBarBorderHeight,
boolean searchBarShadowVisible, float searchBarShadowOpacity,
boolean quickActionIconVisible, boolean thumbnailVisible, String thumbnailUrl,
float customImageVisibilityPercentage, int barImageSize, float arrowIconOpacity,
float arrowIconRotation, float closeIconOpacity, boolean isProgressBarVisible,
float progressBarHeight, float progressBarOpacity, int progressBarCompletion,
float dividerLineVisibilityPercentage, float dividerLineWidth, float dividerLineHeight,
int dividerLineColor, float dividerLineXOffset, boolean touchHighlightVisible,
float touchHighlightXOffset, float toucHighlightWidth, int barHandleResId,
float barHandleOffsetY, float barPaddingBottom, Profile profile);
 
Example #6
Source File: DownloadNotificationService.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
void cancelOffTheRecordDownloads() {
    boolean cancelActualDownload =
            BrowserStartupController.get(LibraryProcessType.PROCESS_BROWSER)
                    .isStartupSuccessfullyCompleted()
            && Profile.getLastUsedProfile().hasOffTheRecordProfile();

    List<DownloadSharedPreferenceEntry> entries = mDownloadSharedPreferenceHelper.getEntries();
    List<DownloadSharedPreferenceEntry> copies =
            new ArrayList<DownloadSharedPreferenceEntry>(entries);
    for (DownloadSharedPreferenceEntry entry : copies) {
        if (!entry.isOffTheRecord) continue;
        ContentId id = entry.id;
        notifyDownloadCanceled(id);
        if (cancelActualDownload) {
            DownloadServiceDelegate delegate = getServiceDelegate(id);
            delegate.cancelDownload(id, true);
            delegate.destroyServiceDelegate();
        }
        for (Observer observer : mObservers) observer.onDownloadCanceled(id);
    }
}
 
Example #7
Source File: WarmupManager.java    From delion with Apache License 2.0 6 votes vote down vote up
/** Asynchronously preconnects to a given URL if the data reduction proxy is not in use.
 *
 * @param profile The profile to use for the preconnection.
 * @param url The URL we want to preconnect to.
 */
public void maybePreconnectUrlAndSubResources(Profile profile, String url) {
    ThreadUtils.assertOnUiThread();
    if (!DataReductionProxySettings.getInstance().isDataReductionProxyEnabled()) {
        // If there is already a DNS request in flight for this URL, then
        // the preconnection will start by issuing a DNS request for the
        // same domain, as the result is not cached. However, such a DNS
        // request has already been sent from this class, so it is better to
        // wait for the answer to come back before preconnecting. Otherwise,
        // the preconnection logic will wait for the result of the second
        // DNS request, which should arrive after the result of the first
        // one. Note that we however need to wait for the main thread to be
        // available in this case, since the preconnection will be sent from
        // AsyncTask.onPostExecute(), which may delay it.
        if (mDnsRequestsInFlight.contains(url)) {
            // Note that if two requests come for the same URL with two
            // different profiles, the last one will win.
            mPendingPreconnectWithProfile.put(url, profile);
        } else {
            nativePreconnectUrlAndSubresources(profile, url);
        }
    }
}
 
Example #8
Source File: SyncController.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Updates sync to reflect the state of the Android sync settings.
 */
private void updateSyncStateFromAndroid() {
    boolean isSyncEnabled = AndroidSyncSettings.isSyncEnabled(mContext);
    if (isSyncEnabled == mProfileSyncService.isSyncRequested()) return;
    if (isSyncEnabled) {
        mProfileSyncService.requestStart();
    } else {
        if (Profile.getLastUsedProfile().isChild()) {
            // For child accounts, Sync needs to stay enabled, so we reenable it in settings.
            // TODO(bauerb): Remove the dependency on child account code and instead go through
            // prefs (here and in the Sync customization UI).
            AndroidSyncSettings.enableChromeSync(mContext);
        } else {
            if (AndroidSyncSettings.isMasterSyncEnabled(mContext)) {
                RecordHistogram.recordEnumeratedHistogram("Sync.StopSource",
                        StopSource.ANDROID_CHROME_SYNC, StopSource.STOP_SOURCE_LIMIT);
            } else {
                RecordHistogram.recordEnumeratedHistogram("Sync.StopSource",
                        StopSource.ANDROID_MASTER_SYNC, StopSource.STOP_SOURCE_LIMIT);
            }
            mProfileSyncService.requestStop();
        }
    }
}
 
Example #9
Source File: WarmupManager.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/** Asynchronously preconnects to a given URL if the data reduction proxy is not in use.
 *
 * @param profile The profile to use for the preconnection.
 * @param url The URL we want to preconnect to.
 */
public void maybePreconnectUrlAndSubResources(Profile profile, String url) {
    ThreadUtils.assertOnUiThread();
    if (!DataReductionProxySettings.getInstance().isDataReductionProxyEnabled()) {
        // If there is already a DNS request in flight for this URL, then
        // the preconnection will start by issuing a DNS request for the
        // same domain, as the result is not cached. However, such a DNS
        // request has already been sent from this class, so it is better to
        // wait for the answer to come back before preconnecting. Otherwise,
        // the preconnection logic will wait for the result of the second
        // DNS request, which should arrive after the result of the first
        // one. Note that we however need to wait for the main thread to be
        // available in this case, since the preconnection will be sent from
        // AsyncTask.onPostExecute(), which may delay it.
        if (mDnsRequestsInFlight.contains(url)) {
            // Note that if two requests come for the same URL with two
            // different profiles, the last one will win.
            mPendingPreconnectWithProfile.put(url, profile);
        } else {
            nativePreconnectUrlAndSubresources(profile, url);
        }
    }
}
 
Example #10
Source File: AccountManagementFragment.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
public void update() {
    final Context context = getActivity();
    if (context == null) return;

    if (getPreferenceScreen() != null) getPreferenceScreen().removeAll();

    ChromeSigninController signInController = ChromeSigninController.get(context);
    if (!signInController.isSignedIn()) {
        // The AccountManagementFragment can only be shown when the user is signed in. If the
        // user is signed out, exit the fragment.
        getActivity().finish();
        return;
    }

    addPreferencesFromResource(R.xml.account_management_preferences);

    String signedInAccountName =
            ChromeSigninController.get(getActivity()).getSignedInAccountName();
    String fullName = getCachedUserName(signedInAccountName);
    if (TextUtils.isEmpty(fullName)) {
        fullName = ProfileDownloader.getCachedFullName(Profile.getLastUsedProfile());
    }
    if (TextUtils.isEmpty(fullName)) fullName = signedInAccountName;

    getActivity().setTitle(fullName);

    configureSignOutSwitch();
    configureAddAccountPreference();
    configureChildAccountPreferences();
    configureSyncSettings();
    configureGoogleActivityControls();

    updateAccountsList();
}
 
Example #11
Source File: AccountManagementScreenHelper.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@CalledByNative
private static void openAccountManagementScreen(Profile profile, int gaiaServiceType) {
    ThreadUtils.assertOnUiThread();

    if (gaiaServiceType == GAIA_SERVICE_TYPE_SIGNUP) {
        openAndroidAccountCreationScreen();
        return;
    }

    AccountManagementFragment.openAccountManagementScreen(gaiaServiceType);
}
 
Example #12
Source File: InvalidationServiceFactory.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Returns Java InvalidationService for the given Profile.
 */
public static InvalidationService getForProfile(Profile profile) {
    ThreadUtils.assertOnUiThread();
    InvalidationService service = sServiceMap.get(profile);
    if (service == null) {
        service = nativeGetForProfile(profile);
        sServiceMap.put(profile, service);
    }
    return service;
}
 
Example #13
Source File: PassphraseCreationDialogFragment.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private SpannableString getInstructionsText() {
    final Activity activity = getActivity();
    return SpanApplier.applySpans(
            activity.getString(R.string.sync_custom_passphrase),
            new SpanInfo("<learnmore>", "</learnmore>", new ClickableSpan() {
                @Override
                public void onClick(View view) {
                    HelpAndFeedback.getInstance(activity).show(activity,
                            activity.getString(R.string.help_context_change_sync_passphrase),
                            Profile.getLastUsedProfile(), null);
                }
            }));
}
 
Example #14
Source File: DataReductionPreferences.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.menu_id_targeted_help) {
        HelpAndFeedback.getInstance(getActivity())
                .show(getActivity(), getString(R.string.help_context_data_reduction),
                        Profile.getLastUsedProfile(), null);
        return true;
    }
    return false;
}
 
Example #15
Source File: UsbChooserPreferences.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.menu_id_targeted_help) {
        HelpAndFeedback.getInstance(getActivity())
                .show(getActivity(), getString(R.string.help_context_settings),
                        Profile.getLastUsedProfile(), null);
        return true;
    }
    return false;
}
 
Example #16
Source File: SuggestionsNavigationDelegateImpl.java    From 365browser with Apache License 2.0 5 votes vote down vote up
public SuggestionsNavigationDelegateImpl(ChromeActivity activity, Profile profile,
        NativePageHost host, TabModelSelector tabModelSelector) {
    mActivity = activity;
    mProfile = profile;
    mHost = host;
    mTabModelSelector = tabModelSelector;
}
 
Example #17
Source File: ConnectivityTask.java    From delion with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
ConnectivityTask(Profile profile, int timeoutMs, ConnectivityResult callback) {
    mTimeoutMs = timeoutMs;
    mCallback = callback;
    mStartCheckTimeMs = SystemClock.elapsedRealtime();
    init(profile, timeoutMs);
}
 
Example #18
Source File: DomDistillerServiceFactory.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Returns Java DomDistillerService for given Profile.
 */
public static DomDistillerService getForProfile(Profile profile) {
    ThreadUtils.assertOnUiThread();
    DomDistillerService service = sServiceMap.get(profile);
    if (service == null) {
        service = nativeGetForProfile(profile);
        sServiceMap.put(profile, service);
    }
    return service;
}
 
Example #19
Source File: FeedbackCollector.java    From delion with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
FeedbackCollector(Activity activity, Profile profile, String url, FeedbackResult callback) {
    mData = new HashMap<>();
    mProfile = profile;
    mUrl = url;
    mCallback = callback;
    mCollectionStartTime = SystemClock.elapsedRealtime();
    init(activity);
}
 
Example #20
Source File: RecentTabsManager.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Create an RecentTabsManager to be used with RecentTabsPage and RecentTabsRowAdapter.
 *
 * @param tab The Tab that is showing this recent tabs page.
 * @param profile Profile that is associated with the current session.
 * @param context the Android context this manager will work in.
 */
public RecentTabsManager(Tab tab, Profile profile, Context context) {
    mProfile = profile;
    mTab = tab;
    mForeignSessionHelper = new ForeignSessionHelper(profile);
    mPrefs = new RecentTabsPagePrefs(profile);
    mFaviconHelper = new FaviconHelper();
    mRecentlyClosedTabManager = sRecentlyClosedTabManagerForTests != null
            ? sRecentlyClosedTabManagerForTests
            : new RecentlyClosedBridge(profile);
    mSignInManager = SigninManager.get(context);
    mContext = context;

    mRecentlyClosedTabManager.setTabsUpdatedRunnable(new Runnable() {
        @Override
        public void run() {
            updateRecentlyClosedTabs();
            postUpdate();
        }
    });

    updateRecentlyClosedTabs();
    registerForForeignSessionUpdates();
    updateForeignSessions();
    mForeignSessionHelper.triggerSessionSync();
    registerForSignInAndSyncNotifications();

    InvalidationController.get(mContext).onRecentTabsPageOpened();
}
 
Example #21
Source File: FirstRunActivity.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public ProfileDataCache getProfileDataCache() {
    if (mProfileDataCache == null) {
        mProfileDataCache =
                new ProfileDataCache(FirstRunActivity.this, Profile.getLastUsedProfile());
    }
    return mProfileDataCache;
}
 
Example #22
Source File: CookiesFetcher.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Ensure the incognito cookies are deleted when the incognito profile is gone.
 *
 * @param context Context for accessing the file system.
 * @return Whether or not the cookies were deleted.
 */
public static boolean deleteCookiesIfNecessary(Context context) {
    try {
        if (Profile.getLastUsedProfile().hasOffTheRecordProfile()) return false;
        scheduleDeleteCookiesFile(context);
    } catch (RuntimeException e) {
        e.printStackTrace();
        return false;
    }
    return true;
}
 
Example #23
Source File: AccountManagementFragment.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Initiate fetching of an image and a picture of a given account. Fetched data will be sent to
 * observers of ProfileDownloader.
 *
 * @param context A context.
 * @param profile A profile.
 * @param accountName An account name.
 */
public static void startFetchingAccountInformation(
        Context context, Profile profile, String accountName) {
    if (TextUtils.isEmpty(accountName)) return;
    if (sToNamePicture.get(accountName) != null) return;

    final int imageSidePixels =
            context.getResources().getDimensionPixelOffset(R.dimen.user_picture_size);
    ProfileDownloader.startFetchingAccountInfoFor(
            context, profile, accountName, imageSidePixels, false);
}
 
Example #24
Source File: IncognitoBottomSheetContent.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a new IncognitoBottomSheetContent.
 * @param activity The {@link Activity} displaying this bottom sheet content.
 */
public IncognitoBottomSheetContent(final Activity activity) {
    LayoutInflater inflater = LayoutInflater.from(activity);
    mView = inflater.inflate(R.layout.incognito_bottom_sheet_content, null);

    View learnMore = mView.findViewById(R.id.learn_more);
    learnMore.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            HelpAndFeedback.getInstance(activity).show(activity,
                    activity.getString(R.string.help_context_incognito_learn_more),
                    Profile.getLastUsedProfile(), null);
        }
    });

    final FadingShadowView shadow = (FadingShadowView) mView.findViewById(R.id.shadow);
    shadow.init(
            ApiCompatibilityUtils.getColor(mView.getResources(), R.color.toolbar_shadow_color),
            FadingShadow.POSITION_TOP);

    mScrollView = (ScrollView) mView.findViewById(R.id.scroll_view);
    mScrollView.getViewTreeObserver().addOnScrollChangedListener(new OnScrollChangedListener() {
        @Override
        public void onScrollChanged() {
            boolean shadowVisible = mScrollView.canScrollVertically(-1);
            shadow.setVisibility(shadowVisible ? View.VISIBLE : View.GONE);
        }
    });
}
 
Example #25
Source File: DataReductionPreferences.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.menu_id_targeted_help) {
        HelpAndFeedback.getInstance(getActivity())
                .show(getActivity(), getString(R.string.help_context_data_reduction),
                        Profile.getLastUsedProfile(), null);
        return true;
    }
    return false;
}
 
Example #26
Source File: ClearBrowsingDataPreferences.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Set the texts that notify the user about data in their google account and that deleting
 * cookies doesn't sign you out of chrome.
 */
protected void initFootnote() {
    // The general information footnote informs users about data that will not be deleted.
    // If the user is signed in, it also informs users about the behavior of synced deletions.
    // and we show an additional Google-specific footnote. This footnote informs users that they
    // will not be signed out of their Google account, and if the web history service indicates
    // that they have other forms of browsing history, then also about that.
    TextMessageWithLinkAndIconPreference google_summary =
            (TextMessageWithLinkAndIconPreference) findPreference(PREF_GOOGLE_SUMMARY);
    TextMessageWithLinkAndIconPreference general_summary =
            (TextMessageWithLinkAndIconPreference) findPreference(PREF_GENERAL_SUMMARY);

    google_summary.setLinkClickDelegate(new Runnable() {
        @Override
        public void run() {
            new TabDelegate(false /* incognito */).launchUrl(
                    WEB_HISTORY_URL, TabLaunchType.FROM_CHROME_UI);
        }
    });
    general_summary.setLinkClickDelegate(new Runnable() {
        @Override
        public void run() {
            HelpAndFeedback.getInstance(getActivity()).show(
                    getActivity(),
                    getResources().getString(R.string.help_context_clear_browsing_data),
                    Profile.getLastUsedProfile(),
                    null);
        }
    });
    if (ChromeSigninController.get().isSignedIn()) {
        general_summary.setSummary(
                R.string.clear_browsing_data_footnote_sync_and_site_settings);
    } else {
        getPreferenceScreen().removePreference(google_summary);
        general_summary.setSummary(R.string.clear_browsing_data_footnote_site_settings);
    }
}
 
Example #27
Source File: ToolbarModelImpl.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public Profile getProfile() {
    Profile lastUsedProfile = Profile.getLastUsedProfile();
    if (mIsIncognito) {
        assert lastUsedProfile.hasOffTheRecordProfile();
        return lastUsedProfile.getOffTheRecordProfile();
    }
    return lastUsedProfile.getOriginalProfile();
}
 
Example #28
Source File: AccountManagementFragment.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Initiate fetching the user accounts data (images and the full name).
 * Fetched data will be sent to observers of ProfileDownloader.
 *
 * @param profile Profile to use.
 */
private static void startFetchingAccountsInformation(Context context, Profile profile) {
    Account[] accounts = AccountManagerHelper.get(context).getGoogleAccounts();
    for (int i = 0; i < accounts.length; i++) {
        startFetchingAccountInformation(context, profile, accounts[i].name);
    }
}
 
Example #29
Source File: PrivacyPreferences.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.menu_id_targeted_help) {
        HelpAndFeedback.getInstance(getActivity())
                .show(getActivity(), getString(R.string.help_context_privacy),
                        Profile.getLastUsedProfile(), null);
        return true;
    }
    return false;
}
 
Example #30
Source File: TabBase.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * @return The profile associated with this tab.
 */
public Profile getProfile() {
    if (mNativeTabAndroid == 0) return null;
    return nativeGetProfileAndroid(mNativeTabAndroid);
}