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/chromeos/drive/drive_integration_service.h" | 5 #include "chrome/browser/chromeos/drive/drive_integration_service.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "base/threading/sequenced_worker_pool.h" | 10 #include "base/threading/sequenced_worker_pool.h" |
11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/chromeos/drive/debug_info_collector.h" | 12 #include "chrome/browser/chromeos/drive/debug_info_collector.h" |
13 #include "chrome/browser/chromeos/drive/download_handler.h" | 13 #include "chrome/browser/chromeos/drive/download_handler.h" |
14 #include "chrome/browser/chromeos/drive/drive_app_registry.h" | 14 #include "chrome/browser/chromeos/drive/drive_app_registry.h" |
15 #include "chrome/browser/chromeos/drive/file_cache.h" | 15 #include "chrome/browser/chromeos/drive/file_cache.h" |
16 #include "chrome/browser/chromeos/drive/file_system.h" | 16 #include "chrome/browser/chromeos/drive/file_system.h" |
17 #include "chrome/browser/chromeos/drive/file_system_proxy.h" | 17 #include "chrome/browser/chromeos/drive/file_system_proxy.h" |
18 #include "chrome/browser/chromeos/drive/file_system_util.h" | 18 #include "chrome/browser/chromeos/drive/file_system_util.h" |
19 #include "chrome/browser/chromeos/drive/file_write_helper.h" | 19 #include "chrome/browser/chromeos/drive/file_write_helper.h" |
20 #include "chrome/browser/chromeos/drive/job_scheduler.h" | 20 #include "chrome/browser/chromeos/drive/job_scheduler.h" |
21 #include "chrome/browser/chromeos/drive/logging.h" | 21 #include "chrome/browser/chromeos/drive/logging.h" |
| 22 #include "chrome/browser/chromeos/drive/resource_metadata.h" |
| 23 #include "chrome/browser/chromeos/drive/resource_metadata_storage.h" |
22 #include "chrome/browser/download/download_service.h" | 24 #include "chrome/browser/download/download_service.h" |
23 #include "chrome/browser/download/download_service_factory.h" | 25 #include "chrome/browser/download/download_service_factory.h" |
24 #include "chrome/browser/download/download_util.h" | 26 #include "chrome/browser/download/download_util.h" |
25 #include "chrome/browser/drive/drive_api_service.h" | 27 #include "chrome/browser/drive/drive_api_service.h" |
26 #include "chrome/browser/drive/drive_api_util.h" | 28 #include "chrome/browser/drive/drive_api_util.h" |
27 #include "chrome/browser/drive/drive_notification_manager.h" | 29 #include "chrome/browser/drive/drive_notification_manager.h" |
28 #include "chrome/browser/drive/drive_notification_manager_factory.h" | 30 #include "chrome/browser/drive/drive_notification_manager_factory.h" |
29 #include "chrome/browser/drive/gdata_wapi_service.h" | 31 #include "chrome/browser/drive/gdata_wapi_service.h" |
30 #include "chrome/browser/google_apis/auth_service.h" | 32 #include "chrome/browser/google_apis/auth_service.h" |
31 #include "chrome/browser/google_apis/gdata_wapi_url_generator.h" | 33 #include "chrome/browser/google_apis/gdata_wapi_url_generator.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 // (see https://developers.google.com/drive/performance) | 86 // (see https://developers.google.com/drive/performance) |
85 return base::StringPrintf("%s-%s %s (%s) (gzip)", | 87 return base::StringPrintf("%s-%s %s (%s) (gzip)", |
86 kDriveClientName, | 88 kDriveClientName, |
87 version.c_str(), | 89 version.c_str(), |
88 kLibraryInfo, | 90 kLibraryInfo, |
89 os_cpu_info.c_str()); | 91 os_cpu_info.c_str()); |
90 } | 92 } |
91 | 93 |
92 // Initializes FileCache and ResourceMetadata. | 94 // Initializes FileCache and ResourceMetadata. |
93 // Must be run on the same task runner used by |cache| and |resource_metadata|. | 95 // Must be run on the same task runner used by |cache| and |resource_metadata|. |
94 FileError InitializeMetadata(const base::FilePath& cache_root_directory, | 96 FileError InitializeMetadata( |
95 internal::FileCache* cache, | 97 const base::FilePath& cache_root_directory, |
96 internal::ResourceMetadata* resource_metadata) { | 98 internal::ResourceMetadataStorage* metadata_storage, |
| 99 internal::FileCache* cache, |
| 100 internal::ResourceMetadata* resource_metadata) { |
97 if (!file_util::CreateDirectory(cache_root_directory.Append( | 101 if (!file_util::CreateDirectory(cache_root_directory.Append( |
98 util::kMetadataDirectory)) || | 102 util::kMetadataDirectory)) || |
99 !file_util::CreateDirectory(cache_root_directory.Append( | 103 !file_util::CreateDirectory(cache_root_directory.Append( |
100 util::kCacheFileDirectory)) || | 104 util::kCacheFileDirectory)) || |
101 !file_util::CreateDirectory(cache_root_directory.Append( | 105 !file_util::CreateDirectory(cache_root_directory.Append( |
102 util::kTemporaryFileDirectory))) { | 106 util::kTemporaryFileDirectory))) { |
103 LOG(WARNING) << "Failed to create directories."; | 107 LOG(WARNING) << "Failed to create directories."; |
104 return FILE_ERROR_FAILED; | 108 return FILE_ERROR_FAILED; |
105 } | 109 } |
106 | 110 |
107 // Change permissions of cache file directory to u+rwx,og+x (711) in order to | 111 // Change permissions of cache file directory to u+rwx,og+x (711) in order to |
108 // allow archive files in that directory to be mounted by cros-disks. | 112 // allow archive files in that directory to be mounted by cros-disks. |
109 file_util::SetPosixFilePermissions( | 113 file_util::SetPosixFilePermissions( |
110 cache_root_directory.Append(util::kCacheFileDirectory), | 114 cache_root_directory.Append(util::kCacheFileDirectory), |
111 file_util::FILE_PERMISSION_USER_MASK | | 115 file_util::FILE_PERMISSION_USER_MASK | |
112 file_util::FILE_PERMISSION_EXECUTE_BY_GROUP | | 116 file_util::FILE_PERMISSION_EXECUTE_BY_GROUP | |
113 file_util::FILE_PERMISSION_EXECUTE_BY_OTHERS); | 117 file_util::FILE_PERMISSION_EXECUTE_BY_OTHERS); |
114 | 118 |
115 util::MigrateCacheFilesFromOldDirectories(cache_root_directory); | 119 util::MigrateCacheFilesFromOldDirectories(cache_root_directory); |
116 | 120 |
117 if (!cache->Initialize()) { | 121 if (!cache->Initialize()) { |
118 LOG(WARNING) << "Failed to initialize the cache."; | 122 LOG(WARNING) << "Failed to initialize the cache."; |
119 return FILE_ERROR_FAILED; | 123 return FILE_ERROR_FAILED; |
120 } | 124 } |
121 | 125 |
| 126 if (!metadata_storage->Initialize()) { |
| 127 LOG(WARNING) << "Failed to initialize the metadata storage."; |
| 128 return FILE_ERROR_FAILED; |
| 129 } |
| 130 |
122 FileError error = resource_metadata->Initialize(); | 131 FileError error = resource_metadata->Initialize(); |
123 LOG_IF(WARNING, error != FILE_ERROR_OK) | 132 LOG_IF(WARNING, error != FILE_ERROR_OK) |
124 << "Failed to initialize resource metadata. " << FileErrorToString(error); | 133 << "Failed to initialize resource metadata. " << FileErrorToString(error); |
125 return error; | 134 return error; |
126 } | 135 } |
127 | 136 |
128 } // namespace | 137 } // namespace |
129 | 138 |
130 DriveIntegrationService::DriveIntegrationService( | 139 DriveIntegrationService::DriveIntegrationService( |
131 Profile* profile, | 140 Profile* profile, |
(...skipping 18 matching lines...) Expand all Loading... |
150 g_browser_process->system_request_context(), | 159 g_browser_process->system_request_context(), |
151 GURL(google_apis::DriveApiUrlGenerator::kBaseUrlForProduction), | 160 GURL(google_apis::DriveApiUrlGenerator::kBaseUrlForProduction), |
152 GetDriveUserAgent())); | 161 GetDriveUserAgent())); |
153 } else { | 162 } else { |
154 drive_service_.reset(new GDataWapiService( | 163 drive_service_.reset(new GDataWapiService( |
155 g_browser_process->system_request_context(), | 164 g_browser_process->system_request_context(), |
156 GURL(google_apis::GDataWapiUrlGenerator::kBaseUrlForProduction), | 165 GURL(google_apis::GDataWapiUrlGenerator::kBaseUrlForProduction), |
157 GetDriveUserAgent())); | 166 GetDriveUserAgent())); |
158 } | 167 } |
159 scheduler_.reset(new JobScheduler(profile_, drive_service_.get())); | 168 scheduler_.reset(new JobScheduler(profile_, drive_service_.get())); |
| 169 metadata_storage_.reset(new internal::ResourceMetadataStorage( |
| 170 cache_root_directory_.Append(util::kMetadataDirectory), |
| 171 blocking_task_runner_.get())); |
160 cache_.reset(new internal::FileCache( | 172 cache_.reset(new internal::FileCache( |
161 cache_root_directory_.Append(util::kMetadataDirectory), | 173 cache_root_directory_.Append(util::kMetadataDirectory), |
162 cache_root_directory_.Append(util::kCacheFileDirectory), | 174 cache_root_directory_.Append(util::kCacheFileDirectory), |
163 blocking_task_runner_.get(), | 175 blocking_task_runner_.get(), |
164 NULL /* free_disk_space_getter */)); | 176 NULL /* free_disk_space_getter */)); |
165 drive_app_registry_.reset(new DriveAppRegistry(scheduler_.get())); | 177 drive_app_registry_.reset(new DriveAppRegistry(scheduler_.get())); |
166 | 178 |
167 resource_metadata_.reset(new internal::ResourceMetadata( | 179 resource_metadata_.reset(new internal::ResourceMetadata( |
168 cache_root_directory_.Append(util::kMetadataDirectory), | 180 metadata_storage_.get(), blocking_task_runner_)); |
169 blocking_task_runner_)); | |
170 | 181 |
171 file_system_.reset( | 182 file_system_.reset( |
172 test_file_system ? test_file_system : new FileSystem( | 183 test_file_system ? test_file_system : new FileSystem( |
173 profile_, | 184 profile_, |
174 cache_.get(), | 185 cache_.get(), |
175 drive_service_.get(), | 186 drive_service_.get(), |
176 scheduler_.get(), | 187 scheduler_.get(), |
177 resource_metadata_.get(), | 188 resource_metadata_.get(), |
178 blocking_task_runner_.get(), | 189 blocking_task_runner_.get(), |
179 cache_root_directory_.Append(util::kTemporaryFileDirectory))); | 190 cache_root_directory_.Append(util::kTemporaryFileDirectory))); |
(...skipping 11 matching lines...) Expand all Loading... |
191 void DriveIntegrationService::Initialize() { | 202 void DriveIntegrationService::Initialize() { |
192 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 203 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
193 drive_service_->Initialize(profile_); | 204 drive_service_->Initialize(profile_); |
194 file_system_->Initialize(); | 205 file_system_->Initialize(); |
195 | 206 |
196 base::PostTaskAndReplyWithResult( | 207 base::PostTaskAndReplyWithResult( |
197 blocking_task_runner_, | 208 blocking_task_runner_, |
198 FROM_HERE, | 209 FROM_HERE, |
199 base::Bind(&InitializeMetadata, | 210 base::Bind(&InitializeMetadata, |
200 cache_root_directory_, | 211 cache_root_directory_, |
| 212 metadata_storage_.get(), |
201 cache_.get(), | 213 cache_.get(), |
202 resource_metadata_.get()), | 214 resource_metadata_.get()), |
203 base::Bind(&DriveIntegrationService::InitializeAfterMetadataInitialized, | 215 base::Bind(&DriveIntegrationService::InitializeAfterMetadataInitialized, |
204 weak_ptr_factory_.GetWeakPtr())); | 216 weak_ptr_factory_.GetWeakPtr())); |
205 } | 217 } |
206 | 218 |
207 void DriveIntegrationService::Shutdown() { | 219 void DriveIntegrationService::Shutdown() { |
208 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 220 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
209 | 221 |
210 DriveNotificationManager* drive_notification_manager = | 222 DriveNotificationManager* drive_notification_manager = |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 profile, NULL, base::FilePath(), NULL); | 467 profile, NULL, base::FilePath(), NULL); |
456 } else { | 468 } else { |
457 service = factory_for_test_.Run(profile); | 469 service = factory_for_test_.Run(profile); |
458 } | 470 } |
459 | 471 |
460 service->Initialize(); | 472 service->Initialize(); |
461 return service; | 473 return service; |
462 } | 474 } |
463 | 475 |
464 } // namespace drive | 476 } // namespace drive |
OLD | NEW |