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/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 #include "content/public/browser/browser_thread.h" | 40 #include "content/public/browser/browser_thread.h" |
41 #include "webkit/browser/fileapi/external_mount_points.h" | 41 #include "webkit/browser/fileapi/external_mount_points.h" |
42 #include "webkit/common/user_agent/user_agent_util.h" | 42 #include "webkit/common/user_agent/user_agent_util.h" |
43 | 43 |
44 using content::BrowserContext; | 44 using content::BrowserContext; |
45 using content::BrowserThread; | 45 using content::BrowserThread; |
46 | 46 |
47 namespace drive { | 47 namespace drive { |
48 namespace { | 48 namespace { |
49 | 49 |
| 50 // Name of the directory used to store metadata. |
| 51 const base::FilePath::CharType kMetadataDirectory[] = FILE_PATH_LITERAL("meta"); |
| 52 |
| 53 // Name of the directory used to store cached files. |
| 54 const base::FilePath::CharType kCacheFileDirectory[] = |
| 55 FILE_PATH_LITERAL("files"); |
| 56 |
| 57 // Name of the directory used to store temporary files. |
| 58 const base::FilePath::CharType kTemporaryFileDirectory[] = |
| 59 FILE_PATH_LITERAL("tmp"); |
| 60 |
50 // Returns a user agent string used for communicating with the Drive backend, | 61 // Returns a user agent string used for communicating with the Drive backend, |
51 // both WAPI and Drive API. The user agent looks like: | 62 // both WAPI and Drive API. The user agent looks like: |
52 // | 63 // |
53 // chromedrive-<VERSION> chrome-cc/none (<OS_CPU_INFO>) | 64 // chromedrive-<VERSION> chrome-cc/none (<OS_CPU_INFO>) |
54 // chromedrive-24.0.1274.0 chrome-cc/none (CrOS x86_64 0.4.0) | 65 // chromedrive-24.0.1274.0 chrome-cc/none (CrOS x86_64 0.4.0) |
55 // | 66 // |
56 // TODO(satorux): Move this function to somewhere else: crbug.com/151605 | 67 // TODO(satorux): Move this function to somewhere else: crbug.com/151605 |
57 std::string GetDriveUserAgent() { | 68 std::string GetDriveUserAgent() { |
58 const char kDriveClientName[] = "chromedrive"; | 69 const char kDriveClientName[] = "chromedrive"; |
59 | 70 |
(...skipping 17 matching lines...) Expand all Loading... |
77 } | 88 } |
78 | 89 |
79 // Initializes FileCache and ResourceMetadata. | 90 // Initializes FileCache and ResourceMetadata. |
80 // Must be run on the same task runner used by |cache| and |resource_metadata|. | 91 // Must be run on the same task runner used by |cache| and |resource_metadata|. |
81 FileError InitializeMetadata( | 92 FileError InitializeMetadata( |
82 const base::FilePath& cache_root_directory, | 93 const base::FilePath& cache_root_directory, |
83 internal::ResourceMetadataStorage* metadata_storage, | 94 internal::ResourceMetadataStorage* metadata_storage, |
84 internal::FileCache* cache, | 95 internal::FileCache* cache, |
85 internal::ResourceMetadata* resource_metadata) { | 96 internal::ResourceMetadata* resource_metadata) { |
86 if (!file_util::CreateDirectory(cache_root_directory.Append( | 97 if (!file_util::CreateDirectory(cache_root_directory.Append( |
87 util::kMetadataDirectory)) || | 98 kMetadataDirectory)) || |
88 !file_util::CreateDirectory(cache_root_directory.Append( | 99 !file_util::CreateDirectory(cache_root_directory.Append( |
89 util::kCacheFileDirectory)) || | 100 kCacheFileDirectory)) || |
90 !file_util::CreateDirectory(cache_root_directory.Append( | 101 !file_util::CreateDirectory(cache_root_directory.Append( |
91 util::kTemporaryFileDirectory))) { | 102 kTemporaryFileDirectory))) { |
92 LOG(WARNING) << "Failed to create directories."; | 103 LOG(WARNING) << "Failed to create directories."; |
93 return FILE_ERROR_FAILED; | 104 return FILE_ERROR_FAILED; |
94 } | 105 } |
95 | 106 |
96 // Change permissions of cache file directory to u+rwx,og+x (711) in order to | 107 // Change permissions of cache file directory to u+rwx,og+x (711) in order to |
97 // allow archive files in that directory to be mounted by cros-disks. | 108 // allow archive files in that directory to be mounted by cros-disks. |
98 file_util::SetPosixFilePermissions( | 109 file_util::SetPosixFilePermissions( |
99 cache_root_directory.Append(util::kCacheFileDirectory), | 110 cache_root_directory.Append(kCacheFileDirectory), |
100 file_util::FILE_PERMISSION_USER_MASK | | 111 file_util::FILE_PERMISSION_USER_MASK | |
101 file_util::FILE_PERMISSION_EXECUTE_BY_GROUP | | 112 file_util::FILE_PERMISSION_EXECUTE_BY_GROUP | |
102 file_util::FILE_PERMISSION_EXECUTE_BY_OTHERS); | 113 file_util::FILE_PERMISSION_EXECUTE_BY_OTHERS); |
103 | 114 |
104 util::MigrateCacheFilesFromOldDirectories(cache_root_directory); | 115 util::MigrateCacheFilesFromOldDirectories(cache_root_directory, |
| 116 kCacheFileDirectory); |
105 | 117 |
106 if (!metadata_storage->Initialize()) { | 118 if (!metadata_storage->Initialize()) { |
107 LOG(WARNING) << "Failed to initialize the metadata storage."; | 119 LOG(WARNING) << "Failed to initialize the metadata storage."; |
108 return FILE_ERROR_FAILED; | 120 return FILE_ERROR_FAILED; |
109 } | 121 } |
110 | 122 |
111 if (!cache->Initialize()) { | 123 if (!cache->Initialize()) { |
112 LOG(WARNING) << "Failed to initialize the cache."; | 124 LOG(WARNING) << "Failed to initialize the cache."; |
113 return FILE_ERROR_FAILED; | 125 return FILE_ERROR_FAILED; |
114 } | 126 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 blocking_task_runner_.get(), | 170 blocking_task_runner_.get(), |
159 GURL(google_apis::GDataWapiUrlGenerator::kBaseUrlForProduction), | 171 GURL(google_apis::GDataWapiUrlGenerator::kBaseUrlForProduction), |
160 GURL(google_apis::GDataWapiUrlGenerator::kBaseDownloadUrlForProduction), | 172 GURL(google_apis::GDataWapiUrlGenerator::kBaseDownloadUrlForProduction), |
161 GetDriveUserAgent())); | 173 GetDriveUserAgent())); |
162 } | 174 } |
163 scheduler_.reset(new JobScheduler( | 175 scheduler_.reset(new JobScheduler( |
164 profile_->GetPrefs(), | 176 profile_->GetPrefs(), |
165 drive_service_.get(), | 177 drive_service_.get(), |
166 blocking_task_runner_.get())); | 178 blocking_task_runner_.get())); |
167 metadata_storage_.reset(new internal::ResourceMetadataStorage( | 179 metadata_storage_.reset(new internal::ResourceMetadataStorage( |
168 cache_root_directory_.Append(util::kMetadataDirectory), | 180 cache_root_directory_.Append(kMetadataDirectory), |
169 blocking_task_runner_.get())); | 181 blocking_task_runner_.get())); |
170 cache_.reset(new internal::FileCache( | 182 cache_.reset(new internal::FileCache( |
171 metadata_storage_.get(), | 183 metadata_storage_.get(), |
172 cache_root_directory_.Append(util::kCacheFileDirectory), | 184 cache_root_directory_.Append(kCacheFileDirectory), |
173 blocking_task_runner_.get(), | 185 blocking_task_runner_.get(), |
174 NULL /* free_disk_space_getter */)); | 186 NULL /* free_disk_space_getter */)); |
175 drive_app_registry_.reset(new DriveAppRegistry(scheduler_.get())); | 187 drive_app_registry_.reset(new DriveAppRegistry(scheduler_.get())); |
176 | 188 |
177 resource_metadata_.reset(new internal::ResourceMetadata( | 189 resource_metadata_.reset(new internal::ResourceMetadata( |
178 metadata_storage_.get(), blocking_task_runner_)); | 190 metadata_storage_.get(), blocking_task_runner_)); |
179 | 191 |
180 file_system_.reset( | 192 file_system_.reset( |
181 test_file_system ? test_file_system : new FileSystem( | 193 test_file_system ? test_file_system : new FileSystem( |
182 profile_->GetPrefs(), | 194 profile_->GetPrefs(), |
183 cache_.get(), | 195 cache_.get(), |
184 drive_service_.get(), | 196 drive_service_.get(), |
185 scheduler_.get(), | 197 scheduler_.get(), |
186 resource_metadata_.get(), | 198 resource_metadata_.get(), |
187 blocking_task_runner_.get(), | 199 blocking_task_runner_.get(), |
188 cache_root_directory_.Append(util::kTemporaryFileDirectory))); | 200 cache_root_directory_.Append(kTemporaryFileDirectory))); |
189 download_handler_.reset(new DownloadHandler(file_system())); | 201 download_handler_.reset(new DownloadHandler(file_system())); |
190 debug_info_collector_.reset( | 202 debug_info_collector_.reset( |
191 new DebugInfoCollector(file_system(), cache_.get())); | 203 new DebugInfoCollector(file_system(), cache_.get())); |
192 } | 204 } |
193 | 205 |
194 DriveIntegrationService::~DriveIntegrationService() { | 206 DriveIntegrationService::~DriveIntegrationService() { |
195 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
196 } | 208 } |
197 | 209 |
198 void DriveIntegrationService::Initialize() { | 210 void DriveIntegrationService::Initialize() { |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 } | 364 } |
353 return; | 365 return; |
354 } | 366 } |
355 is_initialized_ = true; | 367 is_initialized_ = true; |
356 | 368 |
357 content::DownloadManager* download_manager = | 369 content::DownloadManager* download_manager = |
358 g_browser_process->download_status_updater() ? | 370 g_browser_process->download_status_updater() ? |
359 BrowserContext::GetDownloadManager(profile_) : NULL; | 371 BrowserContext::GetDownloadManager(profile_) : NULL; |
360 download_handler_->Initialize( | 372 download_handler_->Initialize( |
361 download_manager, | 373 download_manager, |
362 cache_root_directory_.Append(util::kTemporaryFileDirectory)); | 374 cache_root_directory_.Append(kTemporaryFileDirectory)); |
363 | 375 |
364 // Register for Google Drive invalidation notifications. | 376 // Register for Google Drive invalidation notifications. |
365 DriveNotificationManager* drive_notification_manager = | 377 DriveNotificationManager* drive_notification_manager = |
366 DriveNotificationManagerFactory::GetForBrowserContext(profile_); | 378 DriveNotificationManagerFactory::GetForBrowserContext(profile_); |
367 if (drive_notification_manager) { | 379 if (drive_notification_manager) { |
368 drive_notification_manager->AddObserver(this); | 380 drive_notification_manager->AddObserver(this); |
369 const bool registered = | 381 const bool registered = |
370 drive_notification_manager->push_notification_registered(); | 382 drive_notification_manager->push_notification_registered(); |
371 const char* status = (registered ? "registered" : "not registered"); | 383 const char* status = (registered ? "registered" : "not registered"); |
372 util::Log(logging::LOG_INFO, "Push notification is %s", status); | 384 util::Log(logging::LOG_INFO, "Push notification is %s", status); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 profile, NULL, base::FilePath(), NULL); | 462 profile, NULL, base::FilePath(), NULL); |
451 } else { | 463 } else { |
452 service = factory_for_test_.Run(profile); | 464 service = factory_for_test_.Run(profile); |
453 } | 465 } |
454 | 466 |
455 service->Initialize(); | 467 service->Initialize(); |
456 return service; | 468 return service; |
457 } | 469 } |
458 | 470 |
459 } // namespace drive | 471 } // namespace drive |
OLD | NEW |