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

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

Issue 3133022: sync: take two for: "Added classes to enable session sync... (Closed)
Patch Set: Created 10 years, 4 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
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/histogram.h"
6 #include "base/logging.h"
7 #include "base/time.h"
8 #include "chrome/browser/chrome_thread.h"
9 #include "chrome/browser/sync/glue/session_change_processor.h"
10 #include "chrome/browser/sync/glue/session_data_type_controller.h"
11 #include "chrome/browser/sync/glue/session_model_associator.h"
12 #include "chrome/browser/sync/profile_sync_service.h"
13 #include "chrome/browser/sync/profile_sync_factory.h"
14 #include "chrome/browser/sync/unrecoverable_error_handler.h"
15
16 namespace browser_sync {
17
18 SessionDataTypeController::SessionDataTypeController(
19 ProfileSyncFactory* profile_sync_factory,
20 ProfileSyncService* sync_service)
21 : profile_sync_factory_(profile_sync_factory),
22 sync_service_(sync_service),
23 state_(NOT_RUNNING) {
24 DCHECK(profile_sync_factory);
25 DCHECK(sync_service);
26 }
27
28 SessionDataTypeController::~SessionDataTypeController() {
29 }
30
31 void SessionDataTypeController::Start(StartCallback* start_callback) {
32 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
33 DCHECK(start_callback);
34 if (state_ != NOT_RUNNING) {
35 start_callback->Run(BUSY);
36 delete start_callback;
37 return;
38 }
39
40 start_callback_.reset(start_callback);
41
42 ProfileSyncFactory::SyncComponents sync_components =
43 profile_sync_factory_->CreateSessionSyncComponents(sync_service_,
44 this);
45 model_associator_.reset(sync_components.model_associator);
46 change_processor_.reset(sync_components.change_processor);
47
48 bool sync_has_nodes = false;
49 if (!model_associator_->SyncModelHasUserCreatedNodes(&sync_has_nodes)) {
50 StartFailed(UNRECOVERABLE_ERROR);
51 return;
52 }
53
54 base::TimeTicks start_time = base::TimeTicks::Now();
55 bool success = model_associator_->AssociateModels();
56 UMA_HISTOGRAM_TIMES("Sync.SessionAssociationTime",
57 base::TimeTicks::Now() - start_time);
58 if (!success) {
59 StartFailed(ASSOCIATION_FAILED);
60 return;
61 }
62
63 sync_service_->ActivateDataType(this, change_processor_.get());
64 state_ = RUNNING;
65 FinishStart(!sync_has_nodes ? OK_FIRST_RUN : OK);
66 }
67
68 void SessionDataTypeController::Stop() {
69 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
70
71 if (change_processor_ != NULL)
72 sync_service_->DeactivateDataType(this, change_processor_.get());
73
74 if (model_associator_ != NULL)
75 model_associator_->DisassociateModels();
76
77 change_processor_.reset();
78 model_associator_.reset();
79 start_callback_.reset();
80
81 state_ = NOT_RUNNING;
82 }
83
84 void SessionDataTypeController::OnUnrecoverableError(
85 const tracked_objects::Location& from_here,
86 const std::string& message) {
87 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
88 UMA_HISTOGRAM_COUNTS("Sync.SessionRunFailures", 1);
89 sync_service_->OnUnrecoverableError(from_here, message);
90 }
91
92 browser_sync::SessionModelAssociator*
93 SessionDataTypeController::GetModelAssociator() {
94 return static_cast<SessionModelAssociator*>(model_associator_.get());
95 }
96
97 void SessionDataTypeController::FinishStart(StartResult result) {
98 start_callback_->Run(result);
99 start_callback_.reset();
100 }
101
102 void SessionDataTypeController::StartFailed(StartResult result) {
103 model_associator_.reset();
104 change_processor_.reset();
105 start_callback_->Run(result);
106 start_callback_.reset();
107 UMA_HISTOGRAM_ENUMERATION("Sync.SessionStartFailures",
108 result,
109 MAX_START_RESULT);
110 }
111
112 } // namespace browser_sync
113
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/session_data_type_controller.h ('k') | chrome/browser/sync/glue/session_model_associator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698