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

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

Issue 7926001: [Sync] Move change-related methods out of SyncManager::Observer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 9 years, 3 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
« no previous file with comments | « no previous file | chrome/browser/sync/glue/sync_backend_host.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ 5 #ifndef CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_
6 #define CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ 6 #define CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 // Returns the authenticated username of the sync user, or empty if none 217 // Returns the authenticated username of the sync user, or empty if none
218 // exists. It will only exist if the authentication service provider (e.g 218 // exists. It will only exist if the authentication service provider (e.g
219 // GAIA) has confirmed the username is authentic. 219 // GAIA) has confirmed the username is authentic.
220 string16 GetAuthenticatedUsername() const; 220 string16 GetAuthenticatedUsername() const;
221 221
222 // Determines if the underlying sync engine has made any local changes to 222 // Determines if the underlying sync engine has made any local changes to
223 // items that have not yet been synced with the server. 223 // items that have not yet been synced with the server.
224 // ONLY CALL THIS IF OnInitializationComplete was called! 224 // ONLY CALL THIS IF OnInitializationComplete was called!
225 bool HasUnsyncedItems() const; 225 bool HasUnsyncedItems() const;
226 226
227 // Logs the unsynced items.
228 void LogUnsyncedItems(int level) const;
229
230 // Whether or not we are syncing encryption keys. 227 // Whether or not we are syncing encryption keys.
231 bool IsNigoriEnabled() const; 228 bool IsNigoriEnabled() const;
232 229
233 // Whether or not the Nigori node is encrypted using an explicit passphrase. 230 // Whether or not the Nigori node is encrypted using an explicit passphrase.
234 bool IsUsingExplicitPassphrase(); 231 bool IsUsingExplicitPassphrase();
235 232
236 // True if the cryptographer has any keys available to attempt decryption. 233 // True if the cryptographer has any keys available to attempt decryption.
237 // Could mean we've downloaded and loaded Nigori objects, or we bootstrapped 234 // Could mean we've downloaded and loaded Nigori objects, or we bootstrapped
238 // using a token previously received. 235 // using a token previously received.
239 bool IsCryptographerReady(const sync_api::BaseTransaction* trans) const; 236 bool IsCryptographerReady(const sync_api::BaseTransaction* trans) const;
240 237
241 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) const; 238 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) const;
242 239
243 protected: 240 protected:
244 // An enum representing the steps to initializing the SyncBackendHost. 241 // An enum representing the steps to initializing the SyncBackendHost.
245 enum InitializationState { 242 enum InitializationState {
246 NOT_INITIALIZED, // Initialization hasn't completed. 243 NOT_INITIALIZED, // Initialization hasn't completed.
247 DOWNLOADING_NIGORI, // The SyncManager is initialized, but we're fetching 244 DOWNLOADING_NIGORI, // The SyncManager is initialized, but
248 // encryption information before alerting the 245 // we're fetching encryption information.
249 // frontend. 246 REFRESHING_ENCRYPTION, // The SyncManager is initialized, and we
250 INITIALIZED, // Initialization is complete. 247 // have the encryption information, but we
248 // still need to refresh encryption.
249 INITIALIZED, // Initialization is complete.
251 }; 250 };
252 251
253 // The real guts of SyncBackendHost, to keep the public client API clean. 252 // The real guts of SyncBackendHost, to keep the public client API clean.
254 class Core : public base::RefCountedThreadSafe<SyncBackendHost::Core>, 253 class Core : public base::RefCountedThreadSafe<SyncBackendHost::Core>,
255 public sync_api::SyncManager::Observer { 254 public sync_api::SyncManager::Observer {
256 public: 255 public:
257 Core(const std::string& name, SyncBackendHost* backend); 256 Core(const std::string& name, SyncBackendHost* backend);
258 257
259 // SyncManager::Observer implementation. The Core just acts like an air 258 // SyncManager::Observer implementation. The Core just acts like an air
260 // traffic controller here, forwarding incoming messages to appropriate 259 // traffic controller here, forwarding incoming messages to appropriate
261 // landing threads. 260 // landing threads.
262 virtual void OnChangesApplied(
263 syncable::ModelType model_type,
264 const sync_api::BaseTransaction* trans,
265 const sync_api::ImmutableChangeRecordList& changes) OVERRIDE;
266 virtual void OnChangesComplete(
267 syncable::ModelType model_type) OVERRIDE;
268 virtual void OnSyncCycleCompleted( 261 virtual void OnSyncCycleCompleted(
269 const sessions::SyncSessionSnapshot* snapshot) OVERRIDE; 262 const sessions::SyncSessionSnapshot* snapshot) OVERRIDE;
270 virtual void OnInitializationComplete( 263 virtual void OnInitializationComplete(
271 const WeakHandle<JsBackend>& js_backend, 264 const WeakHandle<JsBackend>& js_backend,
272 bool success) OVERRIDE; 265 bool success) OVERRIDE;
273 virtual void OnAuthError( 266 virtual void OnAuthError(
274 const GoogleServiceAuthError& auth_error) OVERRIDE; 267 const GoogleServiceAuthError& auth_error) OVERRIDE;
275 virtual void OnPassphraseRequired( 268 virtual void OnPassphraseRequired(
276 sync_api::PassphraseRequiredReason reason) OVERRIDE; 269 sync_api::PassphraseRequiredReason reason) OVERRIDE;
277 virtual void OnPassphraseAccepted( 270 virtual void OnPassphraseAccepted(
278 const std::string& bootstrap_token) OVERRIDE; 271 const std::string& bootstrap_token) OVERRIDE;
279 virtual void OnStopSyncingPermanently() OVERRIDE; 272 virtual void OnStopSyncingPermanently() OVERRIDE;
280 virtual void OnUpdatedToken(const std::string& token) OVERRIDE; 273 virtual void OnUpdatedToken(const std::string& token) OVERRIDE;
281 virtual void OnClearServerDataFailed() OVERRIDE; 274 virtual void OnClearServerDataFailed() OVERRIDE;
282 virtual void OnClearServerDataSucceeded() OVERRIDE; 275 virtual void OnClearServerDataSucceeded() OVERRIDE;
283 virtual void OnEncryptionComplete( 276 virtual void OnEncryptionComplete(
284 const syncable::ModelTypeSet& encrypted_types); 277 const syncable::ModelTypeSet& encrypted_types);
285 virtual void OnActionableError( 278 virtual void OnActionableError(
286 const browser_sync::SyncProtocolError& sync_error); 279 const browser_sync::SyncProtocolError& sync_error);
287 280
288 struct DoInitializeOptions { 281 struct DoInitializeOptions {
289 DoInitializeOptions( 282 DoInitializeOptions(
283 MessageLoop* sync_loop,
290 SyncBackendRegistrar* registrar, 284 SyncBackendRegistrar* registrar,
291 const WeakHandle<JsEventHandler>& event_handler, 285 const WeakHandle<JsEventHandler>& event_handler,
292 const GURL& service_url, 286 const GURL& service_url,
293 const scoped_refptr<net::URLRequestContextGetter>& 287 const scoped_refptr<net::URLRequestContextGetter>&
294 request_context_getter, 288 request_context_getter,
295 const sync_api::SyncCredentials& credentials, 289 const sync_api::SyncCredentials& credentials,
296 bool delete_sync_data_folder, 290 bool delete_sync_data_folder,
297 const std::string& restored_key_for_bootstrapping, 291 const std::string& restored_key_for_bootstrapping,
298 bool setup_for_test_mode); 292 bool setup_for_test_mode);
299 ~DoInitializeOptions(); 293 ~DoInitializeOptions();
300 294
295 MessageLoop* sync_loop;
301 SyncBackendRegistrar* registrar; 296 SyncBackendRegistrar* registrar;
302 WeakHandle<JsEventHandler> event_handler; 297 WeakHandle<JsEventHandler> event_handler;
303 GURL service_url; 298 GURL service_url;
304 scoped_refptr<net::URLRequestContextGetter> request_context_getter; 299 scoped_refptr<net::URLRequestContextGetter> request_context_getter;
305 sync_api::SyncCredentials credentials; 300 sync_api::SyncCredentials credentials;
306 std::string lsid; 301 std::string lsid;
307 bool delete_sync_data_folder; 302 bool delete_sync_data_folder;
308 std::string restored_key_for_bootstrapping; 303 std::string restored_key_for_bootstrapping;
309 bool setup_for_test_mode; 304 bool setup_for_test_mode;
310 }; 305 };
311 306
312 // Note: 307 // Note:
313 // 308 //
314 // The Do* methods are the various entry points from our SyncBackendHost. 309 // The Do* methods are the various entry points from our
315 // It calls us on a dedicated thread to actually perform synchronous 310 // SyncBackendHost. They are all called on the sync thread to
316 // (and potentially blocking) syncapi operations. 311 // actually perform synchronous (and potentially blocking) syncapi
312 // operations.
317 // 313 //
318 // Called on the SyncBackendHost sync_thread_ to perform initialization 314 // Called to perform initialization of the syncapi on behalf of
319 // of the syncapi on behalf of SyncBackendHost::Initialize. 315 // SyncBackendHost::Initialize.
320 void DoInitialize(const DoInitializeOptions& options); 316 void DoInitialize(const DoInitializeOptions& options);
321 317
322 // Called on our SyncBackendHost's sync_thread_ to perform credential 318 // Called to perform credential update on behalf of
323 // update on behalf of SyncBackendHost::UpdateCredentials 319 // SyncBackendHost::UpdateCredentials
324 void DoUpdateCredentials(const sync_api::SyncCredentials& credentials); 320 void DoUpdateCredentials(const sync_api::SyncCredentials& credentials);
325 321
326 // Called when the user disables or enables a sync type. 322 // Called when the user disables or enables a sync type.
327 void DoUpdateEnabledTypes(); 323 void DoUpdateEnabledTypes();
328 324
329 // Called on the SyncBackendHost sync_thread_ to tell the syncapi to start 325 // Called to tell the syncapi to start syncing (generally after
330 // syncing (generally after initialization and authentication). 326 // initialization and authentication).
331 void DoStartSyncing(); 327 void DoStartSyncing();
332 328
333 // Called on the SyncBackendHost sync_thread_ to clear server 329 // Called to clear server data.
334 // data.
335 void DoRequestClearServerData(); 330 void DoRequestClearServerData();
336 331
337 // Called on the SyncBackendHost sync_thread_ to cleanup disabled 332 // Called to cleanup disabled types.
338 // types.
339 void DoRequestCleanupDisabledTypes(); 333 void DoRequestCleanupDisabledTypes();
340 334
341 // Called on our SyncBackendHost's |sync_thread_| to set the passphrase 335 // Called to set the passphrase on behalf of
342 // on behalf of SyncBackendHost::SupplyPassphrase. 336 // SyncBackendHost::SupplyPassphrase.
343 void DoSetPassphrase(const std::string& passphrase, bool is_explicit); 337 void DoSetPassphrase(const std::string& passphrase, bool is_explicit);
344 338
345 // Called on SyncBackendHost's |sync_thread_| to turn on encryption of all 339 // Called to turn on encryption of all sync data as well as
346 // sync data as well as reencrypt everything. 340 // reencrypt everything.
347 void DoEnableEncryptEverything(); 341 void DoEnableEncryptEverything();
348 342
343 // Called to refresh encryption with the most recent passphrase
344 // and set of encrypted types. |done_callback| is called on the
345 // sync thread.
346 void DoRefreshEncryption(const base::Closure& done_callback);
347
349 // The shutdown order is a bit complicated: 348 // The shutdown order is a bit complicated:
350 // 1) From |sync_thread_|, invoke the syncapi Shutdown call to do 349 // 1) From |sync_thread_|, invoke the syncapi Shutdown call to do
351 // a final SaveChanges, and close sqlite handles. 350 // a final SaveChanges, and close sqlite handles.
352 // 2) Then, from |frontend_loop_|, halt the sync_thread_ (which is 351 // 2) Then, from |frontend_loop_|, halt the sync_thread_ (which is
353 // a blocking call). This causes syncapi thread-exit handlers 352 // a blocking call). This causes syncapi thread-exit handlers
354 // to run and make use of cached pointers to various components 353 // to run and make use of cached pointers to various components
355 // owned implicitly by us. 354 // owned implicitly by us.
356 // 3) Destroy this Core. That will delete syncapi components in a 355 // 3) Destroy this Core. That will delete syncapi components in a
357 // safe order because the thread that was using them has exited 356 // safe order because the thread that was using them has exited
358 // (in step 2). 357 // (in step 2).
359 void DoShutdown(bool stopping_sync); 358 void DoShutdown(bool stopping_sync);
360 359
361 // Posts a config request on the sync thread.
362 virtual void DoRequestConfig( 360 virtual void DoRequestConfig(
363 const syncable::ModelTypeBitSet& types_to_config, 361 const syncable::ModelTypeBitSet& types_to_config,
364 sync_api::ConfigureReason reason); 362 sync_api::ConfigureReason reason);
365 363
366 // Start the configuration mode. 364 // Start the configuration mode. |callback| is called on the sync
365 // thread.
367 virtual void DoStartConfiguration(Callback0::Type* callback); 366 virtual void DoStartConfiguration(Callback0::Type* callback);
368 367
369 // Set the base request context to use when making HTTP calls. 368 // Set the base request context to use when making HTTP calls.
370 // This method will add a reference to the context to persist it 369 // This method will add a reference to the context to persist it
371 // on the IO thread. Must be removed from IO thread. 370 // on the IO thread. Must be removed from IO thread.
372 371
373 sync_api::SyncManager* sync_manager() { return sync_manager_.get(); } 372 sync_api::SyncManager* sync_manager() { return sync_manager_.get(); }
374 373
375 // Delete the sync data folder to cleanup backend data. Happens the first 374 // Delete the sync data folder to cleanup backend data. Happens the first
376 // time sync is enabled for a user (to prevent accidentally reusing old 375 // time sync is enabled for a user (to prevent accidentally reusing old
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 void HandleClearServerDataFailedOnFrontendLoop(); 441 void HandleClearServerDataFailedOnFrontendLoop();
443 442
444 void FinishConfigureDataTypesOnFrontendLoop(); 443 void FinishConfigureDataTypesOnFrontendLoop();
445 444
446 // Name used for debugging. 445 // Name used for debugging.
447 const std::string name_; 446 const std::string name_;
448 447
449 // Our parent SyncBackendHost 448 // Our parent SyncBackendHost
450 SyncBackendHost* host_; 449 SyncBackendHost* host_;
451 450
451 // The loop where all the sync backend operations happen.
452 // Non-NULL only between calls to DoInitialize() and DoShutdown().
453 MessageLoop* sync_loop_;
454
452 // Our parent's registrar (not owned). Non-NULL only between 455 // Our parent's registrar (not owned). Non-NULL only between
453 // calls to DoInitialize() and DoShutdown(). 456 // calls to DoInitialize() and DoShutdown().
454 SyncBackendRegistrar* registrar_; 457 SyncBackendRegistrar* registrar_;
455 458
456 // The timer used to periodically call SaveChanges. 459 // The timer used to periodically call SaveChanges.
457 base::RepeatingTimer<Core> save_changes_timer_; 460 base::RepeatingTimer<Core> save_changes_timer_;
458 461
459 // The top-level syncapi entry point. Lives on the sync thread. 462 // The top-level syncapi entry point. Lives on the sync thread.
460 scoped_ptr<sync_api::SyncManager> sync_manager_; 463 scoped_ptr<sync_api::SyncManager> sync_manager_;
461 464
(...skipping 12 matching lines...) Expand all
474 void FinishConfigureDataTypesOnFrontendLoop(); 477 void FinishConfigureDataTypesOnFrontendLoop();
475 478
476 // Allows tests to perform alternate core initialization work. 479 // Allows tests to perform alternate core initialization work.
477 virtual void InitCore(const Core::DoInitializeOptions& options); 480 virtual void InitCore(const Core::DoInitializeOptions& options);
478 481
479 // Factory method for HttpPostProviderFactories. Should be 482 // Factory method for HttpPostProviderFactories. Should be
480 // thread-safe. 483 // thread-safe.
481 virtual sync_api::HttpPostProviderFactory* MakeHttpBridgeFactory( 484 virtual sync_api::HttpPostProviderFactory* MakeHttpBridgeFactory(
482 const scoped_refptr<net::URLRequestContextGetter>& getter); 485 const scoped_refptr<net::URLRequestContextGetter>& getter);
483 486
484 MessageLoop* sync_loop() { return sync_thread_.message_loop(); }
485
486 // Helpers to persist a token that can be used to bootstrap sync encryption 487 // Helpers to persist a token that can be used to bootstrap sync encryption
487 // across browser restart to avoid requiring the user to re-enter their 488 // across browser restart to avoid requiring the user to re-enter their
488 // passphrase. |token| must be valid UTF-8 as we use the PrefService for 489 // passphrase. |token| must be valid UTF-8 as we use the PrefService for
489 // storage. 490 // storage.
490 void PersistEncryptionBootstrapToken(const std::string& token); 491 void PersistEncryptionBootstrapToken(const std::string& token);
491 std::string RestoreEncryptionBootstrapToken(); 492 std::string RestoreEncryptionBootstrapToken();
492 493
493 // Our core, which communicates directly to the syncapi. 494 // Our core, which communicates directly to the syncapi.
494 scoped_refptr<Core> core_; 495 scoped_refptr<Core> core_;
495 496
(...skipping 13 matching lines...) Expand all
509 syncable::ModelTypeSet types_to_add; 510 syncable::ModelTypeSet types_to_add;
510 511
511 // Additional details about which types were added. 512 // Additional details about which types were added.
512 syncable::ModelTypeSet added_types; 513 syncable::ModelTypeSet added_types;
513 sync_api::ConfigureReason reason; 514 sync_api::ConfigureReason reason;
514 }; 515 };
515 516
516 // For convenience, checks if initialization state is INITIALIZED. 517 // For convenience, checks if initialization state is INITIALIZED.
517 bool initialized() const { return initialization_state_ == INITIALIZED; } 518 bool initialized() const { return initialization_state_ == INITIALIZED; }
518 519
520 // Must be called on |frontend_loop_|. |done_callback| is called on
521 // |frontend_loop_|.
522 void RefreshEncryption(const base::Closure& done_callback);
523
519 // A thread where all the sync operations happen. 524 // A thread where all the sync operations happen.
520 base::Thread sync_thread_; 525 base::Thread sync_thread_;
521 526
522 // A reference to the MessageLoop used to construct |this|, so we know how 527 // A reference to the MessageLoop used to construct |this|, so we know how
523 // to safely talk back to the SyncFrontend. 528 // to safely talk back to the SyncFrontend.
524 MessageLoop* const frontend_loop_; 529 MessageLoop* const frontend_loop_;
525 530
526 Profile* const profile_; 531 Profile* const profile_;
527 532
528 // Name used for debugging (set from profile_->GetDebugName()). 533 // Name used for debugging (set from profile_->GetDebugName()).
(...skipping 17 matching lines...) Expand all
546 551
547 // UI-thread cache of the last SyncSessionSnapshot received from syncapi. 552 // UI-thread cache of the last SyncSessionSnapshot received from syncapi.
548 scoped_ptr<sessions::SyncSessionSnapshot> last_snapshot_; 553 scoped_ptr<sessions::SyncSessionSnapshot> last_snapshot_;
549 554
550 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost); 555 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost);
551 }; 556 };
552 557
553 } // namespace browser_sync 558 } // namespace browser_sync
554 559
555 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ 560 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/sync/glue/sync_backend_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698