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" |
11 #include "base/location.h" | 11 #include "base/location.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/message_loop_proxy.h" | 13 #include "base/message_loop_proxy.h" |
14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "chrome/browser/google_apis/gdata_wapi_service.h" | |
17 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/sync_file_system/drive_file_sync_client.h" | 17 #include "chrome/browser/sync_file_system/drive_file_sync_client.h" |
19 #include "chrome/browser/sync_file_system/drive_file_sync_util.h" | 18 #include "chrome/browser/sync_file_system/drive_file_sync_util.h" |
20 #include "chrome/browser/sync_file_system/drive_metadata_store.h" | 19 #include "chrome/browser/sync_file_system/drive_metadata_store.h" |
21 #include "chrome/browser/sync_file_system/sync_file_system.pb.h" | 20 #include "chrome/browser/sync_file_system/sync_file_system.pb.h" |
22 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
23 #include "net/base/escape.h" | 22 #include "net/base/escape.h" |
24 #include "webkit/fileapi/file_system_url.h" | 23 #include "webkit/fileapi/file_system_url.h" |
25 #include "webkit/fileapi/syncable/sync_file_metadata.h" | 24 #include "webkit/fileapi/syncable/sync_file_metadata.h" |
26 #include "webkit/fileapi/syncable/sync_file_type.h" | 25 #include "webkit/fileapi/syncable/sync_file_type.h" |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
132 } | 131 } |
133 | 132 |
134 DriveFileSyncService::DriveFileSyncService(Profile* profile) | 133 DriveFileSyncService::DriveFileSyncService(Profile* profile) |
135 : last_operation_status_(fileapi::SYNC_STATUS_OK), | 134 : last_operation_status_(fileapi::SYNC_STATUS_OK), |
136 state_(REMOTE_SERVICE_OK), | 135 state_(REMOTE_SERVICE_OK), |
137 largest_changestamp_(0), | 136 largest_changestamp_(0), |
138 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 137 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
139 token_.reset(new TaskToken(AsWeakPtr())); | 138 token_.reset(new TaskToken(AsWeakPtr())); |
140 | 139 |
141 sync_client_.reset(new DriveFileSyncClient(profile)); | 140 sync_client_.reset(new DriveFileSyncClient(profile)); |
141 sync_client_->AddObserver(this); | |
142 | 142 |
143 metadata_store_.reset(new DriveMetadataStore( | 143 metadata_store_.reset(new DriveMetadataStore( |
144 profile->GetPath(), | 144 profile->GetPath(), |
145 content::BrowserThread::GetMessageLoopProxyForThread( | 145 content::BrowserThread::GetMessageLoopProxyForThread( |
146 content::BrowserThread::FILE))); | 146 content::BrowserThread::FILE))); |
147 | 147 |
148 metadata_store_->Initialize( | 148 metadata_store_->Initialize( |
149 base::Bind(&DriveFileSyncService::DidInitializeMetadataStore, AsWeakPtr(), | 149 base::Bind(&DriveFileSyncService::DidInitializeMetadataStore, AsWeakPtr(), |
150 base::Passed(GetToken(FROM_HERE, TASK_TYPE_DATABASE, | 150 base::Passed(GetToken(FROM_HERE, TASK_TYPE_DATABASE, |
151 "Metadata database initialization")))); | 151 "Metadata database initialization")))); |
152 } | 152 } |
153 | 153 |
154 DriveFileSyncService::~DriveFileSyncService() { | 154 DriveFileSyncService::~DriveFileSyncService() { |
155 // Invalidate WeakPtr instances here explicitly to notify TaskToken that we | 155 // Invalidate WeakPtr instances here explicitly to notify TaskToken that we |
156 // can safely discard the token. | 156 // can safely discard the token. |
157 weak_factory_.InvalidateWeakPtrs(); | 157 weak_factory_.InvalidateWeakPtrs(); |
158 sync_client_->RemoveObserver(this); | |
158 token_.reset(); | 159 token_.reset(); |
159 } | 160 } |
160 | 161 |
161 // static | 162 // static |
162 scoped_ptr<DriveFileSyncService> DriveFileSyncService::CreateForTesting( | 163 scoped_ptr<DriveFileSyncService> DriveFileSyncService::CreateForTesting( |
163 scoped_ptr<DriveFileSyncClient> sync_client, | 164 scoped_ptr<DriveFileSyncClient> sync_client, |
164 scoped_ptr<DriveMetadataStore> metadata_store) { | 165 scoped_ptr<DriveMetadataStore> metadata_store) { |
165 return make_scoped_ptr(new DriveFileSyncService( | 166 return make_scoped_ptr(new DriveFileSyncService( |
166 sync_client.Pass(), metadata_store.Pass())); | 167 sync_client.Pass(), metadata_store.Pass())); |
167 } | 168 } |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
365 DidApplyLocalChange(token.Pass(), url, google_apis::GDATA_OTHER_ERROR, | 366 DidApplyLocalChange(token.Pass(), url, google_apis::GDATA_OTHER_ERROR, |
366 callback, fileapi::SYNC_STATUS_FAILED); | 367 callback, fileapi::SYNC_STATUS_FAILED); |
367 return; | 368 return; |
368 } | 369 } |
369 } | 370 } |
370 NOTREACHED(); | 371 NOTREACHED(); |
371 DidApplyLocalChange(token.Pass(), url, google_apis::GDATA_OTHER_ERROR, | 372 DidApplyLocalChange(token.Pass(), url, google_apis::GDATA_OTHER_ERROR, |
372 callback, fileapi::SYNC_STATUS_FAILED); | 373 callback, fileapi::SYNC_STATUS_FAILED); |
373 } | 374 } |
374 | 375 |
376 void DriveFileSyncService::OnAuthenticated() { | |
377 FOR_EACH_OBSERVER( | |
378 Observer, observers_, | |
379 OnRemoteServiceStateUpdated(REMOTE_SERVICE_OK, "Authenticated")); | |
kinuko
2012/11/30 08:59:35
DriveFileSyncService is also keeping the current s
nhiroki
2012/11/30 09:08:58
Done.
| |
380 } | |
381 | |
375 // Called by CreateForTesting. | 382 // Called by CreateForTesting. |
376 DriveFileSyncService::DriveFileSyncService( | 383 DriveFileSyncService::DriveFileSyncService( |
377 scoped_ptr<DriveFileSyncClient> sync_client, | 384 scoped_ptr<DriveFileSyncClient> sync_client, |
378 scoped_ptr<DriveMetadataStore> metadata_store) | 385 scoped_ptr<DriveMetadataStore> metadata_store) |
379 : last_operation_status_(fileapi::SYNC_STATUS_OK), | 386 : last_operation_status_(fileapi::SYNC_STATUS_OK), |
380 state_(REMOTE_SERVICE_OK), | 387 state_(REMOTE_SERVICE_OK), |
381 largest_changestamp_(0), | 388 largest_changestamp_(0), |
382 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 389 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
383 token_.reset(new TaskToken(AsWeakPtr())); | 390 token_.reset(new TaskToken(AsWeakPtr())); |
384 sync_client_ = sync_client.Pass(); | 391 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()) | 874 if (found_change == path_to_change->end()) |
868 return; | 875 return; |
869 | 876 |
870 pending_changes_.erase(found_change->second.position_in_queue); | 877 pending_changes_.erase(found_change->second.position_in_queue); |
871 path_to_change->erase(found_change); | 878 path_to_change->erase(found_change); |
872 if (path_to_change->empty()) | 879 if (path_to_change->empty()) |
873 url_to_change_.erase(found_origin); | 880 url_to_change_.erase(found_origin); |
874 } | 881 } |
875 | 882 |
876 } // namespace sync_file_system | 883 } // namespace sync_file_system |
OLD | NEW |