org.chromium.chrome.browser.partnerbookmarks.PartnerBookmarksShim Java Examples

The following examples show how to use org.chromium.chrome.browser.partnerbookmarks.PartnerBookmarksShim. 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: BookmarkAddActivity.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public void finishNativeInitialization() {
    RecordUserAction.record("MobileAddBookmarkViaIntent");

    final String title = getIntent().getStringExtra(EXTRA_TITLE);
    final String url = getIntent().getStringExtra(EXTRA_URL);

    // Partner bookmarks need to be loaded explicitly.
    PartnerBookmarksShim.kickOffReading(this);

    // Store mModel as a member variable so it can't be garbage collected. Otherwise the
    // Runnable might never be run.
    mModel = new BookmarkModel();
    mModel.runAfterBookmarkModelLoaded(new Runnable() {
        @Override
        public void run() {
            BookmarkId bookmarkId = BookmarkUtils.addBookmarkSilently(
                    BookmarkAddActivity.this, mModel, title, url);
            if (bookmarkId != null) {
                BookmarkUtils.startEditActivity(BookmarkAddActivity.this, bookmarkId);
            }
            finish();
        }
    });
}
 
Example #2
Source File: BookmarkAddActivity.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public void finishNativeInitialization() {
    RecordUserAction.record("MobileAddBookmarkViaIntent");

    final String title = getIntent().getStringExtra(EXTRA_TITLE);
    final String url = getIntent().getStringExtra(EXTRA_URL);

    // Partner bookmarks need to be loaded explicitly.
    PartnerBookmarksShim.kickOffReading(this);

    // Store mModel as a member variable so it can't be garbage collected. Otherwise the
    // Runnable might never be run.
    mModel = new BookmarkModel();
    mModel.runAfterBookmarkModelLoaded(new Runnable() {
        @Override
        public void run() {
            BookmarkId bookmarkId = BookmarkUtils.addBookmarkSilently(
                    BookmarkAddActivity.this, mModel, title, url);
            if (bookmarkId != null) {
                BookmarkUtils.startEditActivity(BookmarkAddActivity.this, bookmarkId);
            }
            finish();
        }
    });
}
 
Example #3
Source File: BookmarkAddActivity.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void finishNativeInitialization() {
    RecordUserAction.record("MobileAddBookmarkViaIntent");

    final String title = getIntent().getStringExtra(EXTRA_TITLE);
    final String url = getIntent().getStringExtra(EXTRA_URL);

    // Partner bookmarks need to be loaded explicitly.
    PartnerBookmarksShim.kickOffReading(this);

    // Store mModel as a member variable so it can't be garbage collected. Otherwise the
    // Runnable might never be run.
    mModel = new BookmarkModel();
    mModel.runAfterBookmarkModelLoaded(new Runnable() {
        @Override
        public void run() {
            BookmarkId bookmarkId = BookmarkUtils.addBookmarkSilently(
                    BookmarkAddActivity.this, mModel, title, url);
            if (bookmarkId != null) {
                BookmarkUtils.startEditActivity(BookmarkAddActivity.this, bookmarkId);
            }
            finish();
        }
    });
}
 
Example #4
Source File: BookmarkManager.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an instance of {@link BookmarkManager}. It also initializes resources,
 * bookmark models and jni bridges.
 * @param activity The activity context to use.
 * @param isDialogUi Whether the main bookmarks UI will be shown in a dialog, not a NativePage.
 */
public BookmarkManager(Activity activity, boolean isDialogUi) {
    mActivity = activity;
    mIsDialogUi = isDialogUi;

    mBookmarkModel = new BookmarkModel();
    mMainView = (ViewGroup) mActivity.getLayoutInflater().inflate(R.layout.bookmark_main, null);
    mDrawer = (DrawerLayout) mMainView.findViewById(R.id.bookmark_drawer_layout);
    mDrawerListView = (BookmarkDrawerListView) mMainView.findViewById(
            R.id.bookmark_drawer_list);
    mContentView = (BookmarkContentView) mMainView.findViewById(R.id.bookmark_content_view);
    mViewSwitcher = (ViewSwitcher) mMainView.findViewById(R.id.bookmark_view_switcher);
    mUndoController = new BookmarkUndoController(activity, mBookmarkModel,
            ((SnackbarManageable) activity).getSnackbarManager());
    mSearchView = (BookmarkSearchView) getView().findViewById(R.id.bookmark_search_view);
    mBookmarkModel.addObserver(mBookmarkModelObserver);
    initializeToLoadingState();
    mBookmarkModel.runAfterBookmarkModelLoaded(mModelLoadedRunnable);

    // Load partner bookmarks explicitly. We load partner bookmarks in the deferred startup
    // code, but that might be executed much later. Especially on L, showing loading
    // progress bar blocks that so it won't be loaded. http://crbug.com/429383
    PartnerBookmarksShim.kickOffReading(activity);

    mLargeIconBridge = new LargeIconBridge(Profile.getLastUsedProfile().getOriginalProfile());
    ActivityManager activityManager = ((ActivityManager) ContextUtils
            .getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE));
    int maxSize = Math.min(activityManager.getMemoryClass() / 4 * 1024 * 1024,
            FAVICON_MAX_CACHE_SIZE_BYTES);
    mLargeIconBridge.createCache(maxSize);
}
 
Example #5
Source File: BookmarkWidgetService.java    From delion with Apache License 2.0 5 votes vote down vote up
@UiThread
@SuppressFBWarnings("DM_EXIT")
@Override
public void onCreate() {
    // Required to be applied here redundantly to prevent crashes in the cases where the
    // package data is deleted or the Chrome application forced to stop.
    try {
        ChromeBrowserInitializer.getInstance(mContext).handleSynchronousStartup();
    } catch (ProcessInitException e) {
        Log.e(TAG, "Failed to start browser process.", e);
        // Since the library failed to initialize nothing in the application
        // can work, so kill the whole application not just the activity
        System.exit(-1);
    }
    if (isWidgetNewlyCreated()) {
        RecordUserAction.record("BookmarkNavigatorWidgetAdded");
    }

    // Partner bookmarks need to be loaded explicitly.
    PartnerBookmarksShim.kickOffReading(mContext);

    mBookmarkModel = new BookmarkModel();
    mBookmarkModel.addObserver(new BookmarkModelObserver() {
        @Override
        public void bookmarkModelLoaded() {
            // Do nothing. No need to refresh.
        }

        @Override
        public void bookmarkModelChanged() {
            refreshWidget();
        }
    });
}
 
Example #6
Source File: BookmarkWidgetService.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@UiThread
@SuppressFBWarnings("DM_EXIT")
@Override
public void onCreate() {
    // Required to be applied here redundantly to prevent crashes in the cases where the
    // package data is deleted or the Chrome application forced to stop.
    try {
        ChromeBrowserInitializer.getInstance(mContext).handleSynchronousStartup();
    } catch (ProcessInitException e) {
        Log.e(TAG, "Failed to start browser process.", e);
        // Since the library failed to initialize nothing in the application
        // can work, so kill the whole application not just the activity
        System.exit(-1);
    }
    if (isWidgetNewlyCreated()) {
        RecordUserAction.record("BookmarkNavigatorWidgetAdded");
    }

    // Partner bookmarks need to be loaded explicitly.
    PartnerBookmarksShim.kickOffReading(mContext);

    mBookmarkModel = new BookmarkModel();
    mBookmarkModel.addObserver(new BookmarkModelObserver() {
        @Override
        public void bookmarkModelLoaded() {
            // Do nothing. No need to refresh.
        }

        @Override
        public void bookmarkModelChanged() {
            refreshWidget();
        }
    });
}
 
Example #7
Source File: BookmarkWidgetService.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@UiThread
@SuppressFBWarnings("DM_EXIT")
@Override
public void onCreate() {
    // Required to be applied here redundantly to prevent crashes in the cases where the
    // package data is deleted or the Chrome application forced to stop.
    try {
        ChromeBrowserInitializer.getInstance(mContext).handleSynchronousStartup();
    } catch (ProcessInitException e) {
        Log.e(TAG, "Failed to start browser process.", e);
        // Since the library failed to initialize nothing in the application
        // can work, so kill the whole application not just the activity
        System.exit(-1);
    }
    if (isWidgetNewlyCreated()) {
        RecordUserAction.record("BookmarkNavigatorWidgetAdded");
    }

    // Partner bookmarks need to be loaded explicitly.
    PartnerBookmarksShim.kickOffReading(mContext);

    mBookmarkModel = new BookmarkModel();
    mBookmarkModel.addObserver(new BookmarkModelObserver() {
        @Override
        public void bookmarkModelLoaded() {
            // Do nothing. No need to refresh.
        }

        @Override
        public void bookmarkModelChanged() {
            refreshWidget();
        }
    });
}
 
Example #8
Source File: BookmarkManager.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * Creates an instance of {@link BookmarkManager}. It also initializes resources,
 * bookmark models and jni bridges.
 * @param activity The activity context to use.
 * @param isDialogUi Whether the main bookmarks UI will be shown in a dialog, not a NativePage.
 */
public BookmarkManager(Activity activity, boolean isDialogUi) {
    mActivity = activity;
    mIsDialogUi = isDialogUi;

    mSelectionDelegate = new SelectionDelegate<BookmarkId>() {
        @Override
        public boolean toggleSelectionForItem(BookmarkId bookmark) {
            if (!mBookmarkModel.getBookmarkById(bookmark).isEditable()) return false;
            return super.toggleSelectionForItem(bookmark);
        }
    };

    mBookmarkModel = new BookmarkModel();
    mMainView = (ViewGroup) mActivity.getLayoutInflater().inflate(R.layout.bookmark_main, null);
    mDrawer = (DrawerLayout) mMainView.findViewById(R.id.bookmark_drawer_layout);
    mDrawerListView = (BookmarkDrawerListView) mMainView.findViewById(
            R.id.bookmark_drawer_list);
    mContentView = (BookmarkContentView) mMainView.findViewById(R.id.bookmark_content_view);
    mViewSwitcher = (ViewSwitcher) mMainView.findViewById(R.id.bookmark_view_switcher);
    mUndoController = new BookmarkUndoController(activity, mBookmarkModel,
            ((SnackbarManageable) activity).getSnackbarManager());
    mSearchView = (BookmarkSearchView) getView().findViewById(R.id.bookmark_search_view);
    mBookmarkModel.addObserver(mBookmarkModelObserver);
    initializeToLoadingState();
    mBookmarkModel.runAfterBookmarkModelLoaded(mModelLoadedRunnable);

    // Load partner bookmarks explicitly. We load partner bookmarks in the deferred startup
    // code, but that might be executed much later. Especially on L, showing loading
    // progress bar blocks that so it won't be loaded. http://crbug.com/429383
    PartnerBookmarksShim.kickOffReading(activity);

    mLargeIconBridge = new LargeIconBridge(Profile.getLastUsedProfile().getOriginalProfile());
    ActivityManager activityManager = ((ActivityManager) ContextUtils
            .getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE));
    int maxSize = Math.min(activityManager.getMemoryClass() / 4 * 1024 * 1024,
            FAVICON_MAX_CACHE_SIZE_BYTES);
    mLargeIconBridge.createCache(maxSize);

    RecordUserAction.record("MobileBookmarkManagerOpen");
    if (!isDialogUi) {
        RecordUserAction.record("MobileBookmarkManagerPageOpen");
    }
}
 
Example #9
Source File: DeferredStartupHandler.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * Handle application level deferred startup tasks that can be lazily done after all
 * the necessary initialization has been completed. Any calls requiring network access should
 * probably go here.
 *
 * Keep these tasks short and break up long tasks into multiple smaller tasks, as they run on
 * the UI thread and are blocking. Remember to follow RAIL guidelines, as much as possible, and
 * that most devices are quite slow, so leave enough buffer.
 */
@UiThread
public void initDeferredStartupForApp() {
    if (mDeferredStartupInitializedForApp) return;
    mDeferredStartupInitializedForApp = true;
    ThreadUtils.assertOnUiThread();

    RecordHistogram.recordLongTimesHistogram(
            "UMA.Debug.EnableCrashUpload.DeferredStartUptime2",
            SystemClock.uptimeMillis() - UmaUtils.getForegroundStartTime(),
            TimeUnit.MILLISECONDS);

    mDeferredTasks.add(new Runnable() {
        @Override
        public void run() {
            // Punt all tasks that may block on disk off onto a background thread.
            initAsyncDiskTask();

            AfterStartupTaskUtils.setStartupComplete();

            PartnerBrowserCustomizations.setOnInitializeAsyncFinished(new Runnable() {
                @Override
                public void run() {
                    String homepageUrl = HomepageManager.getHomepageUri(mAppContext);
                    LaunchMetrics.recordHomePageLaunchMetrics(
                            HomepageManager.isHomepageEnabled(mAppContext),
                            NewTabPage.isNTPUrl(homepageUrl), homepageUrl);
                }
            });

            PartnerBookmarksShim.kickOffReading(mAppContext);

            PowerMonitor.create(mAppContext);

            ShareHelper.clearSharedImages();

            OfflinePageUtils.clearSharedOfflineFiles(mAppContext);
        }
    });

    mDeferredTasks.add(new Runnable() {
        @Override
        public void run() {
            // Clear any media notifications that existed when Chrome was last killed.
            MediaCaptureNotificationService.clearMediaNotifications(mAppContext);

            startModerateBindingManagementIfNeeded();

            recordKeyboardLocaleUma();
        }
    });

    mDeferredTasks.add(new Runnable() {
        @Override
        public void run() {
            // Start or stop Physical Web
            PhysicalWeb.onChromeStart();
        }
    });

    final ChromeApplication application = (ChromeApplication) mAppContext;

    mDeferredTasks.add(new Runnable() {
        @Override
        public void run() {
            // Starts syncing with GSA.
            application.createGsaHelper().startSync();
        }
    });

    ProcessInitializationHandler.getInstance().initializeDeferredStartupTasks();
}
 
Example #10
Source File: BookmarkManager.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Creates an instance of {@link BookmarkManager}. It also initializes resources,
 * bookmark models and jni bridges.
 * @param activity The activity context to use.
 * @param isDialogUi Whether the main bookmarks UI will be shown in a dialog, not a NativePage.
 * @param snackbarManager The {@link SnackbarManager} used to display snackbars.
 */
public BookmarkManager(Activity activity, boolean isDialogUi, SnackbarManager snackbarManager) {
    mActivity = activity;
    mIsDialogUi = isDialogUi;

    mSelectionDelegate = new SelectionDelegate<BookmarkId>() {
        @Override
        public boolean toggleSelectionForItem(BookmarkId bookmark) {
            if (!mBookmarkModel.getBookmarkById(bookmark).isEditable()) return false;
            return super.toggleSelectionForItem(bookmark);
        }
    };

    mBookmarkModel = new BookmarkModel();
    mMainView = (ViewGroup) mActivity.getLayoutInflater().inflate(R.layout.bookmark_main, null);

    @SuppressWarnings("unchecked")
    SelectableListLayout<BookmarkId> selectableList =
            (SelectableListLayout<BookmarkId>) mMainView.findViewById(R.id.selectable_list);
    mSelectableListLayout = selectableList;
    mSelectableListLayout.initializeEmptyView(
            VectorDrawableCompat.create(
                    mActivity.getResources(), R.drawable.bookmark_big, mActivity.getTheme()),
            R.string.bookmarks_folder_empty, R.string.bookmark_no_result);

    mAdapter = new BookmarkItemsAdapter(activity);

    mRecyclerView = mSelectableListLayout.initializeRecyclerView(mAdapter);

    mToolbar = (BookmarkActionBar) mSelectableListLayout.initializeToolbar(
            R.layout.bookmark_action_bar, mSelectionDelegate, 0, null, R.id.normal_menu_group,
            R.id.selection_mode_menu_group, R.color.default_primary_color, null);
    mToolbar.initializeSearchView(
            this, R.string.bookmark_action_bar_search, R.id.search_menu_id);

    mSelectableListLayout.configureWideDisplayStyle();

    mUndoController = new BookmarkUndoController(activity, mBookmarkModel, snackbarManager);
    mBookmarkModel.addObserver(mBookmarkModelObserver);
    initializeToLoadingState();
    mBookmarkModel.runAfterBookmarkModelLoaded(mModelLoadedRunnable);

    // Load partner bookmarks explicitly. We load partner bookmarks in the deferred startup
    // code, but that might be executed much later. Especially on L, showing loading
    // progress bar blocks that so it won't be loaded. http://crbug.com/429383
    PartnerBookmarksShim.kickOffReading(activity);

    mLargeIconBridge = new LargeIconBridge(Profile.getLastUsedProfile().getOriginalProfile());
    ActivityManager activityManager = ((ActivityManager) ContextUtils
            .getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE));
    int maxSize = Math.min(activityManager.getMemoryClass() / 4 * 1024 * 1024,
            FAVICON_MAX_CACHE_SIZE_BYTES);
    mLargeIconBridge.createCache(maxSize);

    RecordUserAction.record("MobileBookmarkManagerOpen");
    if (!isDialogUi) {
        RecordUserAction.record("MobileBookmarkManagerPageOpen");
    }

    // TODO(twellington): Remove this when Chrome version 59 is a distant memory and users
    // are unlikely to have the old PREF_SEARCH_HISTORY in shared preferences.
    ContextUtils.getAppSharedPreferences().edit().remove(PREF_SEARCH_HISTORY).apply();
}