OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/sync_file_system/drive_file_sync_service.h" | 5 #include "chrome/browser/sync_file_system/drive_file_sync_service.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 } | 132 } |
133 | 133 |
134 DriveFileSyncService::DriveFileSyncService(Profile* profile) | 134 DriveFileSyncService::DriveFileSyncService(Profile* profile) |
135 : last_operation_status_(fileapi::SYNC_STATUS_OK), | 135 : last_operation_status_(fileapi::SYNC_STATUS_OK), |
136 state_(REMOTE_SERVICE_OK), | 136 state_(REMOTE_SERVICE_OK), |
137 largest_changestamp_(0), | 137 largest_changestamp_(0), |
138 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 138 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
139 token_.reset(new TaskToken(AsWeakPtr())); | 139 token_.reset(new TaskToken(AsWeakPtr())); |
140 | 140 |
141 sync_client_.reset(new DriveFileSyncClient(profile)); | 141 sync_client_.reset(new DriveFileSyncClient(profile)); |
| 142 sync_client_->AddObserver(this); |
142 | 143 |
143 metadata_store_.reset(new DriveMetadataStore( | 144 metadata_store_.reset(new DriveMetadataStore( |
144 profile->GetPath(), | 145 profile->GetPath(), |
145 content::BrowserThread::GetMessageLoopProxyForThread( | 146 content::BrowserThread::GetMessageLoopProxyForThread( |
146 content::BrowserThread::FILE))); | 147 content::BrowserThread::FILE))); |
147 | 148 |
148 metadata_store_->Initialize( | 149 metadata_store_->Initialize( |
149 base::Bind(&DriveFileSyncService::DidInitializeMetadataStore, AsWeakPtr(), | 150 base::Bind(&DriveFileSyncService::DidInitializeMetadataStore, AsWeakPtr(), |
150 base::Passed(GetToken(FROM_HERE, TASK_TYPE_DATABASE, | 151 base::Passed(GetToken(FROM_HERE, TASK_TYPE_DATABASE, |
151 "Metadata database initialization")))); | 152 "Metadata database initialization")))); |
152 } | 153 } |
153 | 154 |
154 DriveFileSyncService::~DriveFileSyncService() { | 155 DriveFileSyncService::~DriveFileSyncService() { |
155 // Invalidate WeakPtr instances here explicitly to notify TaskToken that we | 156 // Invalidate WeakPtr instances here explicitly to notify TaskToken that we |
156 // can safely discard the token. | 157 // can safely discard the token. |
157 weak_factory_.InvalidateWeakPtrs(); | 158 weak_factory_.InvalidateWeakPtrs(); |
| 159 sync_client_->RemoveObserver(this); |
158 token_.reset(); | 160 token_.reset(); |
159 } | 161 } |
160 | 162 |
161 // static | 163 // static |
162 scoped_ptr<DriveFileSyncService> DriveFileSyncService::CreateForTesting( | 164 scoped_ptr<DriveFileSyncService> DriveFileSyncService::CreateForTesting( |
163 scoped_ptr<DriveFileSyncClient> sync_client, | 165 scoped_ptr<DriveFileSyncClient> sync_client, |
164 scoped_ptr<DriveMetadataStore> metadata_store) { | 166 scoped_ptr<DriveMetadataStore> metadata_store) { |
165 return make_scoped_ptr(new DriveFileSyncService( | 167 return make_scoped_ptr(new DriveFileSyncService( |
166 sync_client.Pass(), metadata_store.Pass())); | 168 sync_client.Pass(), metadata_store.Pass())); |
167 } | 169 } |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 DidApplyLocalChange(token.Pass(), url, google_apis::GDATA_OTHER_ERROR, | 367 DidApplyLocalChange(token.Pass(), url, google_apis::GDATA_OTHER_ERROR, |
366 callback, fileapi::SYNC_STATUS_FAILED); | 368 callback, fileapi::SYNC_STATUS_FAILED); |
367 return; | 369 return; |
368 } | 370 } |
369 } | 371 } |
370 NOTREACHED(); | 372 NOTREACHED(); |
371 DidApplyLocalChange(token.Pass(), url, google_apis::GDATA_OTHER_ERROR, | 373 DidApplyLocalChange(token.Pass(), url, google_apis::GDATA_OTHER_ERROR, |
372 callback, fileapi::SYNC_STATUS_FAILED); | 374 callback, fileapi::SYNC_STATUS_FAILED); |
373 } | 375 } |
374 | 376 |
| 377 void DriveFileSyncService::OnAuthenticated() { |
| 378 FOR_EACH_OBSERVER( |
| 379 Observer, observers_, |
| 380 OnRemoteServiceStateUpdated(REMOTE_SERVICE_OK, "Authenticated")); |
| 381 } |
| 382 |
375 // Called by CreateForTesting. | 383 // Called by CreateForTesting. |
376 DriveFileSyncService::DriveFileSyncService( | 384 DriveFileSyncService::DriveFileSyncService( |
377 scoped_ptr<DriveFileSyncClient> sync_client, | 385 scoped_ptr<DriveFileSyncClient> sync_client, |
378 scoped_ptr<DriveMetadataStore> metadata_store) | 386 scoped_ptr<DriveMetadataStore> metadata_store) |
379 : last_operation_status_(fileapi::SYNC_STATUS_OK), | 387 : last_operation_status_(fileapi::SYNC_STATUS_OK), |
380 state_(REMOTE_SERVICE_OK), | 388 state_(REMOTE_SERVICE_OK), |
381 largest_changestamp_(0), | 389 largest_changestamp_(0), |
382 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 390 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
383 token_.reset(new TaskToken(AsWeakPtr())); | 391 token_.reset(new TaskToken(AsWeakPtr())); |
384 sync_client_ = sync_client.Pass(); | 392 sync_client_ = sync_client.Pass(); |
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
867 if (found_change == path_to_change->end()) | 875 if (found_change == path_to_change->end()) |
868 return; | 876 return; |
869 | 877 |
870 pending_changes_.erase(found_change->second.position_in_queue); | 878 pending_changes_.erase(found_change->second.position_in_queue); |
871 path_to_change->erase(found_change); | 879 path_to_change->erase(found_change); |
872 if (path_to_change->empty()) | 880 if (path_to_change->empty()) |
873 url_to_change_.erase(found_origin); | 881 url_to_change_.erase(found_origin); |
874 } | 882 } |
875 | 883 |
876 } // namespace sync_file_system | 884 } // namespace sync_file_system |
OLD | NEW |