@Override
 public void onSavePageLater(String linkUrl) {
   OfflinePageBridge bridge = OfflinePageBridge.getForProfile(mTab.getProfile());
   Random random = new Random();
   long offline_id = random.nextLong();
   ClientId clientId = new ClientId("async_loading", Long.toString(offline_id));
   bridge.savePageLater(linkUrl, clientId);
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    int title =
        OfflinePageBridge.isEnabled() ? R.string.offline_pages_edit_item : R.string.edit_bookmark;
    setTitle(title);
    EnhancedBookmarkUtils.setTaskDescriptionInDocumentMode(this, getString(title));
    mEnhancedBookmarksModel = new EnhancedBookmarksModel();
    mBookmarkId =
        BookmarkId.getBookmarkIdFromString(getIntent().getStringExtra(INTENT_BOOKMARK_ID));
    mEnhancedBookmarksModel.addObserver(mBookmarkModelObserver);
    assert mEnhancedBookmarksModel.getBookmarkById(mBookmarkId).isEditable();

    setContentView(R.layout.eb_edit);
    mTitleEditText = (EmptyAlertEditText) findViewById(R.id.title_text);
    mFolderTextView = (TextView) findViewById(R.id.folder_text);
    mUrlEditText = (EmptyAlertEditText) findViewById(R.id.url_text);

    mFolderTextView.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            EnhancedBookmarkFolderSelectActivity.startFolderSelectActivity(
                EnhancedBookmarkEditActivity.this, mBookmarkId);
          }
        });

    if (OfflinePageBridge.isEnabled()
        && OfflinePageBridge.canSavePage(
            mEnhancedBookmarksModel.getBookmarkById(mBookmarkId).getUrl())) {
      mOfflinePageModelObserver =
          new OfflinePageModelObserver() {
            @Override
            public void offlinePageDeleted(BookmarkId bookmarkId) {
              if (mBookmarkId.equals(bookmarkId)) {
                updateOfflineSection();
              }
            }
          };

      mEnhancedBookmarksModel.getOfflinePageBridge().addObserver(mOfflinePageModelObserver);
      // Make offline page section visible and find controls.
      findViewById(R.id.offline_page_group).setVisibility(View.VISIBLE);
      getIntent().setExtrasClassLoader(WebContents.class.getClassLoader());
      mWebContents = getIntent().getParcelableExtra(INTENT_WEB_CONTENTS);
      mActivityWindowAndroid = new ActivityWindowAndroid(this, false);
      updateOfflineSection();
    }

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    updateViewContent();
  }
  private void updateOfflineSection() {
    assert OfflinePageBridge.isEnabled();
    mEnhancedBookmarksModel.getOfflinePageBridge().checkOfflinePageMetadata();

    Button saveRemoveVisitButton = (Button) findViewById(R.id.offline_page_save_remove_button);
    TextView offlinePageInfoTextView = (TextView) findViewById(R.id.offline_page_info_text);

    OfflinePageItem offlinePage =
        mEnhancedBookmarksModel.getOfflinePageBridge().getPageByBookmarkId(mBookmarkId);
    if (offlinePage != null) {
      // Offline page exists. Show information and button to remove.
      offlinePageInfoTextView.setText(
          getString(
              R.string.bookmark_offline_page_size,
              Formatter.formatFileSize(this, offlinePage.getFileSize())));
      updateButtonToDeleteOfflinePage(saveRemoveVisitButton);
    } else if (mWebContents != null) {
      // Offline page is not saved, but a bookmarked page is opened. Show save button.
      offlinePageInfoTextView.setText(getString(R.string.bookmark_offline_page_none));
      updateButtonToSaveOfflinePage(saveRemoveVisitButton);
    } else {
      // Offline page is not saved, and edit page was opened from the bookmarks UI, which
      // means there is no action the user can take any action - hide button.
      offlinePageInfoTextView.setText(getString(R.string.bookmark_offline_page_visit));
      updateButtonToVisitOfflinePage(saveRemoveVisitButton);
    }
  }
 @Override
 protected void onDestroy() {
   recordOfflineButtonAction(false);
   if (OfflinePageBridge.isEnabled()) {
     mEnhancedBookmarksModel.getOfflinePageBridge().removeObserver(mOfflinePageModelObserver);
   }
   mEnhancedBookmarksModel.removeObserver(mBookmarkModelObserver);
   mEnhancedBookmarksModel.destroy();
   mEnhancedBookmarksModel = null;
   super.onDestroy();
 }