Commit 87a58d93 authored by sky@chromium.org's avatar sky@chromium.org

Changes the visibility of the 'mobile' node based on whether there is a node on the sync side.

BUG=102714
TEST=none

Review URL: http://codereview.chromium.org/8786006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113103 0039d316-1c4b-4281-b951-d872f2087c98
parent 6622841e
...@@ -108,6 +108,8 @@ class MobileNode : public BookmarkNode { ...@@ -108,6 +108,8 @@ class MobileNode : public BookmarkNode {
explicit MobileNode(int64 id); explicit MobileNode(int64 id);
virtual ~MobileNode(); virtual ~MobileNode();
void set_visible(bool value) { visible_ = value; }
// BookmarkNode overrides: // BookmarkNode overrides:
virtual bool IsVisible() const OVERRIDE; virtual bool IsVisible() const OVERRIDE;
...@@ -546,6 +548,11 @@ void BookmarkModel::ClearStore() { ...@@ -546,6 +548,11 @@ void BookmarkModel::ClearStore() {
store_ = NULL; store_ = NULL;
} }
void BookmarkModel::SetMobileFolderVisible(bool value) {
DCHECK(loaded_);
static_cast<MobileNode*>(mobile_node_)->set_visible(value);
}
bool BookmarkModel::IsBookmarkedNoLock(const GURL& url) { bool BookmarkModel::IsBookmarkedNoLock(const GURL& url) {
BookmarkNode tmp_node(url); BookmarkNode tmp_node(url);
return (nodes_ordered_by_url_set_.find(&tmp_node) != return (nodes_ordered_by_url_set_.find(&tmp_node) !=
......
...@@ -329,6 +329,9 @@ class BookmarkModel : public content::NotificationObserver, ...@@ -329,6 +329,9 @@ class BookmarkModel : public content::NotificationObserver,
return expanded_state_tracker_.get(); return expanded_state_tracker_.get();
} }
// Sets whether the mobile folder is visible. This is set by sync.
void SetMobileFolderVisible(bool value);
private: private:
friend class BookmarkCodecTest; friend class BookmarkCodecTest;
friend class BookmarkModelTest; friend class BookmarkModelTest;
......
...@@ -6,11 +6,13 @@ ...@@ -6,11 +6,13 @@
#include <string> #include <string>
#include "base/command_line.h"
#include "chrome/browser/sync/engine/syncer.h" #include "chrome/browser/sync/engine/syncer.h"
#include "chrome/browser/sync/engine/syncer_proto_util.h" #include "chrome/browser/sync/engine/syncer_proto_util.h"
#include "chrome/browser/sync/engine/syncproto.h" #include "chrome/browser/sync/engine/syncproto.h"
#include "chrome/browser/sync/syncable/directory_manager.h" #include "chrome/browser/sync/syncable/directory_manager.h"
#include "chrome/browser/sync/syncable/model_type_payload_map.h" #include "chrome/browser/sync/syncable/model_type_payload_map.h"
#include "chrome/common/chrome_switches.h"
using syncable::ScopedDirLookup; using syncable::ScopedDirLookup;
...@@ -35,8 +37,10 @@ void DownloadUpdatesCommand::ExecuteImpl(SyncSession* session) { ...@@ -35,8 +37,10 @@ void DownloadUpdatesCommand::ExecuteImpl(SyncSession* session) {
ClientToServerMessage::GET_UPDATES); ClientToServerMessage::GET_UPDATES);
GetUpdatesMessage* get_updates = GetUpdatesMessage* get_updates =
client_to_server_message.mutable_get_updates(); client_to_server_message.mutable_get_updates();
// TODO: make this default to true. if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kCreateMobileBookmarksFolder)) {
get_updates->set_include_syncable_bookmarks(true); get_updates->set_include_syncable_bookmarks(true);
}
ScopedDirLookup dir(session->context()->directory_manager(), ScopedDirLookup dir(session->context()->directory_manager(),
session->context()->account_name()); session->context()->account_name());
......
...@@ -451,6 +451,9 @@ void BookmarkChangeProcessor::ApplyChangesFromSyncModel( ...@@ -451,6 +451,9 @@ void BookmarkChangeProcessor::ApplyChangesFromSyncModel(
foster_parent = NULL; foster_parent = NULL;
} }
// The visibility of the mobile node may need to change.
model_associator_->UpdateMobileNodeVisibility();
// We are now ready to hear about bookmarks changes again. // We are now ready to hear about bookmarks changes again.
model->AddObserver(this); model->AddObserver(this);
} }
......
...@@ -186,6 +186,14 @@ BookmarkModelAssociator::~BookmarkModelAssociator() { ...@@ -186,6 +186,14 @@ BookmarkModelAssociator::~BookmarkModelAssociator() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
} }
void BookmarkModelAssociator::UpdateMobileNodeVisibility() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(bookmark_model_->IsLoaded());
bookmark_model_->SetMobileFolderVisible(
id_map_.find(bookmark_model_->mobile_node()->id()) != id_map_.end());
}
bool BookmarkModelAssociator::DisassociateModels(SyncError* error) { bool BookmarkModelAssociator::DisassociateModels(SyncError* error) {
id_map_.clear(); id_map_.clear();
id_map_inverse_.clear(); id_map_inverse_.clear();
...@@ -228,6 +236,7 @@ void BookmarkModelAssociator::Associate(const BookmarkNode* node, ...@@ -228,6 +236,7 @@ void BookmarkModelAssociator::Associate(const BookmarkNode* node,
id_map_inverse_[sync_id] = node; id_map_inverse_[sync_id] = node;
dirty_associations_sync_ids_.insert(sync_id); dirty_associations_sync_ids_.insert(sync_id);
PostPersistAssociationsTask(); PostPersistAssociationsTask();
UpdateMobileNodeVisibility();
} }
void BookmarkModelAssociator::Disassociate(int64 sync_id) { void BookmarkModelAssociator::Disassociate(int64 sync_id) {
...@@ -368,10 +377,15 @@ bool BookmarkModelAssociator::BuildAssociations(SyncError* error) { ...@@ -368,10 +377,15 @@ bool BookmarkModelAssociator::BuildAssociations(SyncError* error) {
error->Reset(FROM_HERE, kServerError, model_type()); error->Reset(FROM_HERE, kServerError, model_type());
return false; return false;
} }
// The mobile folder isn't always present on the backend, so we don't fail if if (!AssociateTaggedPermanentNode(bookmark_model_->mobile_node(),
// it doesn't exist. kMobileBookmarksTag) &&
ignore_result(AssociateTaggedPermanentNode(bookmark_model_->mobile_node(), // The mobile folder only need exist if kCreateMobileBookmarksFolder is
kMobileBookmarksTag)); // set.
CommandLine::ForCurrentProcess()->HasSwitch(
switches::kCreateMobileBookmarksFolder)) {
error->Reset(FROM_HERE, kServerError, model_type());
return false;
}
int64 bookmark_bar_sync_id = GetSyncIdFromChromeId( int64 bookmark_bar_sync_id = GetSyncIdFromChromeId(
bookmark_model_->bookmark_bar_node()->id()); bookmark_model_->bookmark_bar_node()->id());
DCHECK_NE(bookmark_bar_sync_id, sync_api::kInvalidId); DCHECK_NE(bookmark_bar_sync_id, sync_api::kInvalidId);
...@@ -380,6 +394,10 @@ bool BookmarkModelAssociator::BuildAssociations(SyncError* error) { ...@@ -380,6 +394,10 @@ bool BookmarkModelAssociator::BuildAssociations(SyncError* error) {
DCHECK_NE(other_bookmarks_sync_id, sync_api::kInvalidId); DCHECK_NE(other_bookmarks_sync_id, sync_api::kInvalidId);
int64 mobile_bookmarks_sync_id = GetSyncIdFromChromeId( int64 mobile_bookmarks_sync_id = GetSyncIdFromChromeId(
bookmark_model_->mobile_node()->id()); bookmark_model_->mobile_node()->id());
if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kCreateMobileBookmarksFolder)) {
DCHECK_NE(sync_api::kInvalidId, mobile_bookmarks_sync_id);
}
std::stack<int64> dfs_stack; std::stack<int64> dfs_stack;
if (mobile_bookmarks_sync_id != sync_api::kInvalidId) if (mobile_bookmarks_sync_id != sync_api::kInvalidId)
...@@ -523,9 +541,11 @@ bool BookmarkModelAssociator::LoadAssociations() { ...@@ -523,9 +541,11 @@ bool BookmarkModelAssociator::LoadAssociations() {
return false; return false;
} }
int64 mobile_bookmarks_id = -1; int64 mobile_bookmarks_id = -1;
// Can't fail here as the mobile folder may not exist. if (!GetSyncIdForTaggedNode(kMobileBookmarksTag, &mobile_bookmarks_id) &&
ignore_result( CommandLine::ForCurrentProcess()->HasSwitch(
GetSyncIdForTaggedNode(kMobileBookmarksTag, &mobile_bookmarks_id)); switches::kCreateMobileBookmarksFolder)) {
return false;
}
// Build a bookmark node ID index since we are going to repeatedly search for // Build a bookmark node ID index since we are going to repeatedly search for
// bookmark nodes by their IDs. // bookmark nodes by their IDs.
......
...@@ -40,6 +40,10 @@ class BookmarkModelAssociator ...@@ -40,6 +40,10 @@ class BookmarkModelAssociator
UnrecoverableErrorHandler* unrecoverable_error_handler); UnrecoverableErrorHandler* unrecoverable_error_handler);
virtual ~BookmarkModelAssociator(); virtual ~BookmarkModelAssociator();
// Invokes BookmarkModel::SetMobileFolderVisible() based on whether the mobile
// node exists.
void UpdateMobileNodeVisibility();
// AssociatorInterface implementation. // AssociatorInterface implementation.
// //
// AssociateModels iterates through both the sync and the browser // AssociateModels iterates through both the sync and the browser
......
...@@ -296,6 +296,8 @@ class ProfileSyncServiceBookmarkTest : public testing::Test { ...@@ -296,6 +296,8 @@ class ProfileSyncServiceBookmarkTest : public testing::Test {
virtual void SetUp() { virtual void SetUp() {
test_user_share_.SetUp(); test_user_share_.SetUp();
CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kCreateMobileBookmarksFolder);
} }
virtual void TearDown() { virtual void TearDown() {
......
...@@ -190,6 +190,9 @@ const char kCrashOnHangThreads[] = "crash-on-hang-threads"; ...@@ -190,6 +190,9 @@ const char kCrashOnHangThreads[] = "crash-on-hang-threads";
// other threads are not responsive. // other threads are not responsive.
const char kCrashOnLive[] = "crash-on-live"; const char kCrashOnLive[] = "crash-on-live";
// If true the mobile bookmarks folder is created on the sync side.
const char kCreateMobileBookmarksFolder[] = "create-mobile-bookmarks-folder";
// Path to the inspector files on disk (allows reloading of devtool files // Path to the inspector files on disk (allows reloading of devtool files
// without having to restart the browser). // without having to restart the browser).
const char kDebugDevToolsFrontend[] = "debug-devtools-frontend"; const char kDebugDevToolsFrontend[] = "debug-devtools-frontend";
...@@ -567,9 +570,6 @@ const char kEnableSyncTabsForOtherClients[] = ...@@ -567,9 +570,6 @@ const char kEnableSyncTabsForOtherClients[] =
// Enables context menu for selecting groups of tabs. // Enables context menu for selecting groups of tabs.
const char kEnableTabGroupsContextMenu[] = "enable-tab-groups-context-menu"; const char kEnableTabGroupsContextMenu[] = "enable-tab-groups-context-menu";
// Enables the "synced bookmarks" folder.
const char kEnableSyncedBookmarksFolder[] = "enable-synced-bookmarks-folder";
// Spawns threads to watch for excessive delays in specified message loops. // Spawns threads to watch for excessive delays in specified message loops.
// User should set breakpoints on Alarm() to examine problematic thread. // User should set breakpoints on Alarm() to examine problematic thread.
// //
......
...@@ -64,6 +64,7 @@ extern const char kCountry[]; ...@@ -64,6 +64,7 @@ extern const char kCountry[];
extern const char kCrashOnHangSeconds[]; extern const char kCrashOnHangSeconds[];
extern const char kCrashOnHangThreads[]; extern const char kCrashOnHangThreads[];
extern const char kCrashOnLive[]; extern const char kCrashOnLive[];
extern const char kCreateMobileBookmarksFolder[];
extern const char kDebugDevToolsFrontend[]; extern const char kDebugDevToolsFrontend[];
extern const char kDebugEnableFrameToggle[]; extern const char kDebugEnableFrameToggle[];
extern const char kDebugPrint[]; extern const char kDebugPrint[];
...@@ -162,7 +163,6 @@ extern const char kEnableSyncExtensionSettings[]; ...@@ -162,7 +163,6 @@ extern const char kEnableSyncExtensionSettings[];
extern const char kEnableSyncOAuth[]; extern const char kEnableSyncOAuth[];
extern const char kEnableSyncTabs[]; extern const char kEnableSyncTabs[];
extern const char kEnableSyncTabsForOtherClients[]; extern const char kEnableSyncTabsForOtherClients[];
extern const char kEnableSyncedBookmarksFolder[];
extern const char kEnableTabGroupsContextMenu[]; extern const char kEnableTabGroupsContextMenu[];
extern const char kEnableTopSites[]; extern const char kEnableTopSites[];
extern const char kEnableWatchdog[]; extern const char kEnableWatchdog[];
......
...@@ -394,8 +394,6 @@ class SyncDataModel(object): ...@@ -394,8 +394,6 @@ class SyncDataModel(object):
parent_tag='google_chrome_bookmarks', sync_type=BOOKMARK), parent_tag='google_chrome_bookmarks', sync_type=BOOKMARK),
PermanentItem('other_bookmarks', name='Other Bookmarks', PermanentItem('other_bookmarks', name='Other Bookmarks',
parent_tag='google_chrome_bookmarks', sync_type=BOOKMARK), parent_tag='google_chrome_bookmarks', sync_type=BOOKMARK),
PermanentItem('synced_bookmarks', name='Mobile Bookmarks',
parent_tag='google_chrome_bookmarks', sync_type=BOOKMARK),
PermanentItem('google_chrome_preferences', name='Preferences', PermanentItem('google_chrome_preferences', name='Preferences',
parent_tag='google_chrome', sync_type=PREFERENCE), parent_tag='google_chrome', sync_type=PREFERENCE),
PermanentItem('google_chrome_autofill', name='Autofill', PermanentItem('google_chrome_autofill', name='Autofill',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment