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/sync_file_system_service.h" | 5 #include "chrome/browser/sync_file_system/sync_file_system_service.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/profiles/profile_dependency_manager.h" | 11 #include "chrome/browser/profiles/profile_dependency_manager.h" |
12 #include "chrome/browser/sync_file_system/local_file_sync_service.h" | 12 #include "chrome/browser/sync_file_system/local_file_sync_service.h" |
| 13 #include "chrome/browser/sync_file_system/remote_file_sync_service.h" |
13 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
14 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
15 #include "webkit/fileapi/file_system_context.h" | 16 #include "webkit/fileapi/file_system_context.h" |
16 #include "webkit/fileapi/syncable/sync_status_code.h" | 17 #include "webkit/fileapi/syncable/sync_status_code.h" |
17 | 18 |
18 using content::BrowserThread; | 19 using content::BrowserThread; |
19 | 20 |
20 namespace sync_file_system { | 21 namespace sync_file_system { |
21 | 22 |
22 void SyncFileSystemService::Shutdown() { | 23 void SyncFileSystemService::Shutdown() { |
23 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 24 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
24 | 25 |
25 local_file_service_->Shutdown(); | 26 local_file_service_->Shutdown(); |
26 local_file_service_.reset(); | 27 local_file_service_.reset(); |
27 | 28 |
| 29 remote_file_service_.reset(); |
| 30 |
28 profile_ = NULL; | 31 profile_ = NULL; |
29 } | 32 } |
30 | 33 |
31 SyncFileSystemService::~SyncFileSystemService() { | 34 SyncFileSystemService::~SyncFileSystemService() { |
32 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 35 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
33 DCHECK(!profile_); | 36 DCHECK(!profile_); |
34 } | 37 } |
35 | 38 |
36 void SyncFileSystemService::InitializeForApp( | 39 void SyncFileSystemService::InitializeForApp( |
37 fileapi::FileSystemContext* file_system_context, | 40 fileapi::FileSystemContext* file_system_context, |
38 const std::string& service_name, | 41 const std::string& service_name, |
39 const GURL& app_url, | 42 const GURL& app_url, |
40 const StatusCallback& callback) { | 43 const StatusCallback& callback) { |
41 DCHECK(local_file_service_.get()); | 44 DCHECK(local_file_service_); |
42 | 45 |
43 // TODO(kinuko,tzik): Instantiate the remote_file_service for the given | 46 // TODO(kinuko,tzik): Instantiate the remote_file_service for the given |
44 // |service_name| if it hasn't been initialized. | 47 // |service_name| if it hasn't been initialized. |
45 | 48 |
46 local_file_service_->MaybeInitializeFileSystemContext( | 49 local_file_service_->MaybeInitializeFileSystemContext( |
47 app_url, file_system_context, callback); | 50 app_url.GetOrigin(), file_system_context, callback); |
48 | 51 |
49 // TODO(tzik): Hook up remote service initialization code. | 52 // TODO(tzik): Uncomment this line after its implementation lands. |
| 53 // remote_file_service_->RegisterOriginForTrackingChanges( |
| 54 // app_url.GetOrigin()); |
50 } | 55 } |
51 | 56 |
52 SyncFileSystemService::SyncFileSystemService(Profile* profile) | 57 SyncFileSystemService::SyncFileSystemService(Profile* profile) |
53 : profile_(profile) {} | 58 : profile_(profile) {} |
54 | 59 |
55 void SyncFileSystemService::Initialize( | 60 void SyncFileSystemService::Initialize( |
56 scoped_ptr<LocalFileSyncService> local_file_service) { | 61 scoped_ptr<LocalFileSyncService> local_file_service, |
| 62 scoped_ptr<RemoteFileSyncService> remote_file_service) { |
57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
58 DCHECK(local_file_service.get()); | 64 DCHECK(local_file_service.get()); |
59 DCHECK(profile_); | 65 DCHECK(profile_); |
60 | 66 |
61 local_file_service_ = local_file_service.Pass(); | 67 local_file_service_ = local_file_service.Pass(); |
| 68 remote_file_service_ = remote_file_service.Pass(); |
| 69 |
| 70 // TODO(tzik): Uncomment this line after RemoteChangeObserver lands. |
| 71 // remote_file_service_->AddObserver(this); |
62 } | 72 } |
63 | 73 |
64 // SyncFileSystemServiceFactory ----------------------------------------------- | 74 // SyncFileSystemServiceFactory ----------------------------------------------- |
65 | 75 |
66 // static | 76 // static |
67 SyncFileSystemService* SyncFileSystemServiceFactory::GetForProfile( | 77 SyncFileSystemService* SyncFileSystemServiceFactory::GetForProfile( |
68 Profile* profile) { | 78 Profile* profile) { |
69 return static_cast<SyncFileSystemService*>( | 79 return static_cast<SyncFileSystemService*>( |
70 GetInstance()->GetServiceForProfile(profile, true)); | 80 GetInstance()->GetServiceForProfile(profile, true)); |
71 } | 81 } |
(...skipping 12 matching lines...) Expand all Loading... |
84 | 94 |
85 ProfileKeyedService* SyncFileSystemServiceFactory::BuildServiceInstanceFor( | 95 ProfileKeyedService* SyncFileSystemServiceFactory::BuildServiceInstanceFor( |
86 Profile* profile) const { | 96 Profile* profile) const { |
87 SyncFileSystemService* service = new SyncFileSystemService(profile); | 97 SyncFileSystemService* service = new SyncFileSystemService(profile); |
88 | 98 |
89 // TODO(kinuko): Set up mock services if it is called for testing. | 99 // TODO(kinuko): Set up mock services if it is called for testing. |
90 | 100 |
91 scoped_ptr<LocalFileSyncService> local_file_service( | 101 scoped_ptr<LocalFileSyncService> local_file_service( |
92 new LocalFileSyncService); | 102 new LocalFileSyncService); |
93 | 103 |
94 service->Initialize(local_file_service.Pass()); | 104 scoped_ptr<RemoteFileSyncService> remote_file_service; |
| 105 // TODO(tzik): Instantiate DriveFileSyncService. |
| 106 |
| 107 service->Initialize(local_file_service.Pass(), |
| 108 remote_file_service.Pass()); |
95 return service; | 109 return service; |
96 } | 110 } |
97 | 111 |
98 } // namespace chrome | 112 } // namespace sync_file_system |
OLD | NEW |