Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(637)

Side by Side Diff: chrome/browser/sync/glue/sync_backend_host.cc

Issue 6794005: Move sync notifier contruction out of syncer thread. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Rebase Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/task.h" 12 #include "base/task.h"
13 #include "base/threading/thread_restrictions.h" 13 #include "base/threading/thread_restrictions.h"
14 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
15 #include "chrome/browser/net/gaia/token_service.h" 15 #include "chrome/browser/net/gaia/token_service.h"
16 #include "chrome/browser/prefs/pref_service.h" 16 #include "chrome/browser/prefs/pref_service.h"
17 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/sync/engine/syncapi.h" 18 #include "chrome/browser/sync/engine/syncapi.h"
19 #include "chrome/browser/sync/glue/autofill_model_associator.h" 19 #include "chrome/browser/sync/glue/autofill_model_associator.h"
20 #include "chrome/browser/sync/glue/autofill_profile_model_associator.h" 20 #include "chrome/browser/sync/glue/autofill_profile_model_associator.h"
21 #include "chrome/browser/sync/glue/change_processor.h" 21 #include "chrome/browser/sync/glue/change_processor.h"
22 #include "chrome/browser/sync/glue/database_model_worker.h" 22 #include "chrome/browser/sync/glue/database_model_worker.h"
23 #include "chrome/browser/sync/glue/history_model_worker.h" 23 #include "chrome/browser/sync/glue/history_model_worker.h"
24 #include "chrome/browser/sync/glue/http_bridge.h" 24 #include "chrome/browser/sync/glue/http_bridge.h"
25 #include "chrome/browser/sync/glue/password_model_worker.h" 25 #include "chrome/browser/sync/glue/password_model_worker.h"
26 #include "chrome/browser/sync/glue/sync_backend_host.h" 26 #include "chrome/browser/sync/glue/sync_backend_host.h"
27 #include "chrome/browser/sync/js_arg_list.h" 27 #include "chrome/browser/sync/js_arg_list.h"
28 #include "chrome/browser/sync/notifier/sync_notifier.h"
28 #include "chrome/browser/sync/notifier/sync_notifier_factory.h" 29 #include "chrome/browser/sync/notifier/sync_notifier_factory.h"
29 #include "chrome/browser/sync/sessions/session_state.h" 30 #include "chrome/browser/sync/sessions/session_state.h"
30 // TODO(tim): Remove this! We should have a syncapi pass-thru instead. 31 // TODO(tim): Remove this! We should have a syncapi pass-thru instead.
31 #include "chrome/browser/sync/syncable/directory_manager.h" // Cryptographer. 32 #include "chrome/browser/sync/syncable/directory_manager.h" // Cryptographer.
32 #include "chrome/browser/sync/syncable/model_type.h" 33 #include "chrome/browser/sync/syncable/model_type.h"
33 #include "chrome/browser/sync/syncable/nigori_util.h" 34 #include "chrome/browser/sync/syncable/nigori_util.h"
34 #include "chrome/common/chrome_switches.h" 35 #include "chrome/common/chrome_switches.h"
35 #include "chrome/common/chrome_version_info.h" 36 #include "chrome/common/chrome_version_info.h"
36 #include "chrome/common/net/gaia/gaia_constants.h" 37 #include "chrome/common/net/gaia/gaia_constants.h"
37 #include "chrome/common/pref_names.h" 38 #include "chrome/common/pref_names.h"
38 #include "content/browser/browser_thread.h" 39 #include "content/browser/browser_thread.h"
39 #include "content/common/notification_service.h" 40 #include "content/common/notification_service.h"
40 #include "content/common/notification_type.h" 41 #include "content/common/notification_type.h"
41 #include "googleurl/src/gurl.h" 42 #include "googleurl/src/gurl.h"
42 #include "webkit/glue/webkit_glue.h" 43 #include "webkit/glue/webkit_glue.h"
43 44
44 static const int kSaveChangesIntervalSeconds = 10; 45 static const int kSaveChangesIntervalSeconds = 10;
45 static const FilePath::CharType kSyncDataFolderName[] = 46 static const FilePath::CharType kSyncDataFolderName[] =
46 FILE_PATH_LITERAL("Sync Data"); 47 FILE_PATH_LITERAL("Sync Data");
47 48
48 using browser_sync::DataTypeController; 49 using browser_sync::DataTypeController;
50 using sync_notifier::SyncNotifierFactory;
49 typedef TokenService::TokenAvailableDetails TokenAvailableDetails; 51 typedef TokenService::TokenAvailableDetails TokenAvailableDetails;
50 52
51 typedef GoogleServiceAuthError AuthError; 53 typedef GoogleServiceAuthError AuthError;
52 54
53 namespace browser_sync { 55 namespace browser_sync {
54 56
55 using sessions::SyncSessionSnapshot; 57 using sessions::SyncSessionSnapshot;
56 using sync_api::SyncCredentials; 58 using sync_api::SyncCredentials;
57 59
58 SyncBackendHost::SyncBackendHost(Profile* profile) 60 SyncBackendHost::SyncBackendHost(Profile* profile)
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 return core_->syncapi()->HasUnsyncedItems(); 693 return core_->syncapi()->HasUnsyncedItems();
692 } 694 }
693 695
694 SyncBackendHost::Core::Core(SyncBackendHost* backend) 696 SyncBackendHost::Core::Core(SyncBackendHost* backend)
695 : host_(backend), 697 : host_(backend),
696 syncapi_(new sync_api::SyncManager()), 698 syncapi_(new sync_api::SyncManager()),
697 sync_manager_observer_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 699 sync_manager_observer_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
698 parent_router_(NULL), 700 parent_router_(NULL),
699 processing_passphrase_(false), 701 processing_passphrase_(false),
700 deferred_nudge_for_cleanup_requested_(false) { 702 deferred_nudge_for_cleanup_requested_(false) {
703 const std::string& client_info = webkit_glue::GetUserAgent(GURL());
704 SyncNotifierFactory sync_notifier_factory(client_info);
705 sync_notifier_.reset(sync_notifier_factory.CreateSyncNotifier(
706 *CommandLine::ForCurrentProcess()));
701 } 707 }
702 708
703 // Helper to construct a user agent string (ASCII) suitable for use by 709 // Helper to construct a user agent string (ASCII) suitable for use by
704 // the syncapi for any HTTP communication. This string is used by the sync 710 // the syncapi for any HTTP communication. This string is used by the sync
705 // backend for classifying client types when calculating statistics. 711 // backend for classifying client types when calculating statistics.
706 std::string MakeUserAgentForSyncapi() { 712 std::string MakeUserAgentForSyncapi() {
707 std::string user_agent; 713 std::string user_agent;
708 user_agent = "Chrome "; 714 user_agent = "Chrome ";
709 #if defined(OS_WIN) 715 #if defined(OS_WIN)
710 user_agent += "WIN "; 716 user_agent += "WIN ";
(...skipping 29 matching lines...) Expand all
740 DeleteSyncDataFolder(); 746 DeleteSyncDataFolder();
741 } 747 }
742 748
743 // Make sure that the directory exists before initializing the backend. 749 // Make sure that the directory exists before initializing the backend.
744 // If it already exists, this will do no harm. 750 // If it already exists, this will do no harm.
745 bool success = file_util::CreateDirectory(host_->sync_data_folder_path()); 751 bool success = file_util::CreateDirectory(host_->sync_data_folder_path());
746 DCHECK(success); 752 DCHECK(success);
747 753
748 syncapi_->AddObserver(this); 754 syncapi_->AddObserver(this);
749 const FilePath& path_str = host_->sync_data_folder_path(); 755 const FilePath& path_str = host_->sync_data_folder_path();
750 const std::string& client_info = webkit_glue::GetUserAgent(GURL());
751 sync_notifier::SyncNotifierFactory sync_notifier_factory(client_info);
752 success = syncapi_->Init( 756 success = syncapi_->Init(
753 path_str, 757 path_str,
754 (options.service_url.host() + options.service_url.path()).c_str(), 758 (options.service_url.host() + options.service_url.path()).c_str(),
755 options.service_url.EffectiveIntPort(), 759 options.service_url.EffectiveIntPort(),
756 options.service_url.SchemeIsSecure(), 760 options.service_url.SchemeIsSecure(),
757 options.http_bridge_factory, 761 options.http_bridge_factory,
758 host_, // ModelSafeWorkerRegistrar. 762 host_, // ModelSafeWorkerRegistrar.
759 MakeUserAgentForSyncapi().c_str(), 763 MakeUserAgentForSyncapi().c_str(),
760 options.credentials, 764 options.credentials,
761 sync_notifier_factory.CreateSyncNotifier( 765 sync_notifier_.get(),
762 *CommandLine::ForCurrentProcess()),
763 options.restored_key_for_bootstrapping, 766 options.restored_key_for_bootstrapping,
764 options.setup_for_test_mode); 767 options.setup_for_test_mode);
765 DCHECK(success) << "Syncapi initialization failed!"; 768 DCHECK(success) << "Syncapi initialization failed!";
766 } 769 }
767 770
768 void SyncBackendHost::Core::DoUpdateCredentials( 771 void SyncBackendHost::Core::DoUpdateCredentials(
769 const SyncCredentials& credentials) { 772 const SyncCredentials& credentials) {
770 DCHECK(MessageLoop::current() == host_->core_thread_.message_loop()); 773 DCHECK(MessageLoop::current() == host_->core_thread_.message_loop());
771 syncapi_->UpdateCredentials(credentials); 774 syncapi_->UpdateCredentials(credentials);
772 } 775 }
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
1185 DCHECK_EQ(MessageLoop::current(), host_->core_thread_.message_loop()); 1188 DCHECK_EQ(MessageLoop::current(), host_->core_thread_.message_loop());
1186 syncapi_->GetJsBackend()->ProcessMessage(name, args, sender); 1189 syncapi_->GetJsBackend()->ProcessMessage(name, args, sender);
1187 } 1190 }
1188 1191
1189 void SyncBackendHost::Core::DeferNudgeForCleanup() { 1192 void SyncBackendHost::Core::DeferNudgeForCleanup() {
1190 DCHECK_EQ(MessageLoop::current(), host_->core_thread_.message_loop()); 1193 DCHECK_EQ(MessageLoop::current(), host_->core_thread_.message_loop());
1191 deferred_nudge_for_cleanup_requested_ = true; 1194 deferred_nudge_for_cleanup_requested_ = true;
1192 } 1195 }
1193 1196
1194 } // namespace browser_sync 1197 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/sync_backend_host.h ('k') | chrome/browser/sync/notifier/non_blocking_invalidation_notifier.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698