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

Side by Side Diff: chrome/browser/sync_file_system/drive_file_sync_service.cc

Issue 11414253: DriveFileSyncService listens to OnAuthenticated event to recover from unavailable state (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years 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 | « chrome/browser/sync_file_system/drive_file_sync_service.h ('k') | no next file » | 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) 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/file_util.h" 11 #include "base/file_util.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "base/message_loop_proxy.h" 14 #include "base/message_loop_proxy.h"
15 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "chrome/browser/google_apis/gdata_wapi_service.h"
18 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/sync_file_system/drive_file_sync_client.h" 18 #include "chrome/browser/sync_file_system/drive_file_sync_client.h"
20 #include "chrome/browser/sync_file_system/drive_file_sync_util.h" 19 #include "chrome/browser/sync_file_system/drive_file_sync_util.h"
21 #include "chrome/browser/sync_file_system/drive_metadata_store.h" 20 #include "chrome/browser/sync_file_system/drive_metadata_store.h"
22 #include "chrome/browser/sync_file_system/remote_change_processor.h" 21 #include "chrome/browser/sync_file_system/remote_change_processor.h"
23 #include "chrome/browser/sync_file_system/sync_file_system.pb.h" 22 #include "chrome/browser/sync_file_system/sync_file_system.pb.h"
24 #include "content/public/browser/browser_thread.h" 23 #include "content/public/browser/browser_thread.h"
25 #include "net/base/escape.h" 24 #include "net/base/escape.h"
26 #include "webkit/fileapi/file_system_url.h" 25 #include "webkit/fileapi/file_system_url.h"
27 #include "webkit/fileapi/syncable/sync_file_metadata.h" 26 #include "webkit/fileapi/syncable/sync_file_metadata.h"
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 DriveFileSyncService::DriveFileSyncService(Profile* profile) 201 DriveFileSyncService::DriveFileSyncService(Profile* profile)
203 : last_operation_status_(fileapi::SYNC_STATUS_OK), 202 : last_operation_status_(fileapi::SYNC_STATUS_OK),
204 state_(REMOTE_SERVICE_OK), 203 state_(REMOTE_SERVICE_OK),
205 largest_changestamp_(0), 204 largest_changestamp_(0),
206 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 205 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
207 temporary_file_dir_ = 206 temporary_file_dir_ =
208 profile->GetPath().Append(kSyncFileSystemDir).Append(kTempDirName); 207 profile->GetPath().Append(kSyncFileSystemDir).Append(kTempDirName);
209 token_.reset(new TaskToken(AsWeakPtr())); 208 token_.reset(new TaskToken(AsWeakPtr()));
210 209
211 sync_client_.reset(new DriveFileSyncClient(profile)); 210 sync_client_.reset(new DriveFileSyncClient(profile));
211 sync_client_->AddObserver(this);
212 212
213 metadata_store_.reset(new DriveMetadataStore( 213 metadata_store_.reset(new DriveMetadataStore(
214 profile->GetPath().Append(kSyncFileSystemDir), 214 profile->GetPath().Append(kSyncFileSystemDir),
215 content::BrowserThread::GetMessageLoopProxyForThread( 215 content::BrowserThread::GetMessageLoopProxyForThread(
216 content::BrowserThread::FILE))); 216 content::BrowserThread::FILE)));
217 217
218 metadata_store_->Initialize( 218 metadata_store_->Initialize(
219 base::Bind(&DriveFileSyncService::DidInitializeMetadataStore, AsWeakPtr(), 219 base::Bind(&DriveFileSyncService::DidInitializeMetadataStore, AsWeakPtr(),
220 base::Passed(GetToken(FROM_HERE, TASK_TYPE_DATABASE, 220 base::Passed(GetToken(FROM_HERE, TASK_TYPE_DATABASE,
221 "Metadata database initialization")))); 221 "Metadata database initialization"))));
222 } 222 }
223 223
224 DriveFileSyncService::~DriveFileSyncService() { 224 DriveFileSyncService::~DriveFileSyncService() {
225 // Invalidate WeakPtr instances here explicitly to notify TaskToken that we 225 // Invalidate WeakPtr instances here explicitly to notify TaskToken that we
226 // can safely discard the token. 226 // can safely discard the token.
227 weak_factory_.InvalidateWeakPtrs(); 227 weak_factory_.InvalidateWeakPtrs();
228 sync_client_->RemoveObserver(this);
228 token_.reset(); 229 token_.reset();
229 } 230 }
230 231
231 // static 232 // static
232 scoped_ptr<DriveFileSyncService> DriveFileSyncService::CreateForTesting( 233 scoped_ptr<DriveFileSyncService> DriveFileSyncService::CreateForTesting(
233 const FilePath& base_dir, 234 const FilePath& base_dir,
234 scoped_ptr<DriveFileSyncClient> sync_client, 235 scoped_ptr<DriveFileSyncClient> sync_client,
235 scoped_ptr<DriveMetadataStore> metadata_store) { 236 scoped_ptr<DriveMetadataStore> metadata_store) {
236 return make_scoped_ptr(new DriveFileSyncService( 237 return make_scoped_ptr(new DriveFileSyncService(
237 base_dir, sync_client.Pass(), metadata_store.Pass())); 238 base_dir, sync_client.Pass(), metadata_store.Pass()));
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 DidApplyLocalChange(token.Pass(), url, google_apis::GDATA_OTHER_ERROR, 490 DidApplyLocalChange(token.Pass(), url, google_apis::GDATA_OTHER_ERROR,
490 callback, fileapi::SYNC_STATUS_FAILED); 491 callback, fileapi::SYNC_STATUS_FAILED);
491 return; 492 return;
492 } 493 }
493 } 494 }
494 NOTREACHED(); 495 NOTREACHED();
495 DidApplyLocalChange(token.Pass(), url, google_apis::GDATA_OTHER_ERROR, 496 DidApplyLocalChange(token.Pass(), url, google_apis::GDATA_OTHER_ERROR,
496 callback, fileapi::SYNC_STATUS_FAILED); 497 callback, fileapi::SYNC_STATUS_FAILED);
497 } 498 }
498 499
500 void DriveFileSyncService::OnAuthenticated() {
501 DVLOG(1) << "OnAuthenticated";
502 state_ = REMOTE_SERVICE_OK;
503 FOR_EACH_OBSERVER(
504 Observer, observers_,
505 OnRemoteServiceStateUpdated(REMOTE_SERVICE_OK, "Authenticated"));
kinuko 2012/11/30 09:49:35 nit: I'd use state_ instead.
nhiroki 2012/11/30 10:43:36 Done.
506 }
507
499 // Called by CreateForTesting. 508 // Called by CreateForTesting.
500 DriveFileSyncService::DriveFileSyncService( 509 DriveFileSyncService::DriveFileSyncService(
501 const FilePath& base_dir, 510 const FilePath& base_dir,
502 scoped_ptr<DriveFileSyncClient> sync_client, 511 scoped_ptr<DriveFileSyncClient> sync_client,
503 scoped_ptr<DriveMetadataStore> metadata_store) 512 scoped_ptr<DriveMetadataStore> metadata_store)
504 : last_operation_status_(fileapi::SYNC_STATUS_OK), 513 : last_operation_status_(fileapi::SYNC_STATUS_OK),
505 state_(REMOTE_SERVICE_OK), 514 state_(REMOTE_SERVICE_OK),
506 largest_changestamp_(0), 515 largest_changestamp_(0),
507 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 516 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
508 temporary_file_dir_ = base_dir.Append(kTempDirName); 517 temporary_file_dir_ = base_dir.Append(kTempDirName);
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after
1318 return false; 1327 return false;
1319 const PathToChange& path_to_change = found_url->second; 1328 const PathToChange& path_to_change = found_url->second;
1320 PathToChange::const_iterator found_path = path_to_change.find(url.path()); 1329 PathToChange::const_iterator found_path = path_to_change.find(url.path());
1321 if (found_path == path_to_change.end()) 1330 if (found_path == path_to_change.end())
1322 return false; 1331 return false;
1323 *change = found_path->second; 1332 *change = found_path->second;
1324 return true; 1333 return true;
1325 } 1334 }
1326 1335
1327 } // namespace sync_file_system 1336 } // namespace sync_file_system
OLDNEW
« no previous file with comments | « chrome/browser/sync_file_system/drive_file_sync_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698