| 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/file_system_util.h" | 5 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> |
| 8 | 9 |
| 9 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 10 #include "base/bind.h" | 11 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 12 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 13 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
| 14 #include "base/i18n/icu_string_conversions.h" | 15 #include "base/i18n/icu_string_conversions.h" |
| 15 #include "base/json/json_file_value_serializer.h" | 16 #include "base/json/json_file_value_serializer.h" |
| 16 #include "base/logging.h" | 17 #include "base/logging.h" |
| 17 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/message_loop/message_loop_proxy.h" | 19 #include "base/message_loop/message_loop_proxy.h" |
| 19 #include "base/prefs/pref_service.h" | 20 #include "base/prefs/pref_service.h" |
| 20 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
| 21 #include "base/strings/string_util.h" | 22 #include "base/strings/string_util.h" |
| 22 #include "base/strings/stringprintf.h" | 23 #include "base/strings/stringprintf.h" |
| 23 #include "base/threading/sequenced_worker_pool.h" | 24 #include "base/threading/sequenced_worker_pool.h" |
| 24 #include "chrome/browser/browser_process.h" | 25 #include "chrome/browser/browser_process.h" |
| 25 #include "chrome/browser/chromeos/drive/drive.pb.h" | 26 #include "chrome/browser/chromeos/drive/drive.pb.h" |
| 26 #include "chrome/browser/chromeos/drive/drive_integration_service.h" | 27 #include "chrome/browser/chromeos/drive/drive_integration_service.h" |
| 27 #include "chrome/browser/chromeos/drive/file_system_interface.h" | 28 #include "chrome/browser/chromeos/drive/file_system_interface.h" |
| 28 #include "chrome/browser/chromeos/drive/job_list.h" | 29 #include "chrome/browser/chromeos/drive/job_list.h" |
| 29 #include "chrome/browser/chromeos/drive/write_on_cache_file.h" | 30 #include "chrome/browser/chromeos/drive/write_on_cache_file.h" |
| 30 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 31 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 31 #include "chrome/browser/chromeos/profiles/profile_util.h" | 32 #include "chrome/browser/chromeos/profiles/profile_util.h" |
| 32 #include "chrome/browser/profiles/profile.h" | 33 #include "chrome/browser/profiles/profile.h" |
| 33 #include "chrome/browser/profiles/profile_manager.h" | 34 #include "chrome/browser/profiles/profile_manager.h" |
| 34 #include "chrome/common/chrome_constants.h" | 35 #include "chrome/common/chrome_constants.h" |
| 35 #include "chrome/common/chrome_paths_internal.h" | 36 #include "chrome/common/chrome_paths_internal.h" |
| 36 #include "chrome/common/pref_names.h" | 37 #include "chrome/common/pref_names.h" |
| 37 #include "chrome/common/url_constants.h" | |
| 38 #include "chromeos/chromeos_constants.h" | 38 #include "chromeos/chromeos_constants.h" |
| 39 #include "components/user_manager/user_manager.h" | 39 #include "components/user_manager/user_manager.h" |
| 40 #include "content/public/browser/browser_thread.h" | 40 #include "content/public/browser/browser_thread.h" |
| 41 #include "net/base/escape.h" | 41 #include "net/base/escape.h" |
| 42 #include "storage/browser/fileapi/file_system_url.h" | 42 #include "storage/browser/fileapi/file_system_url.h" |
| 43 | 43 |
| 44 using content::BrowserThread; | 44 using content::BrowserThread; |
| 45 | 45 |
| 46 namespace drive { | 46 namespace drive { |
| 47 namespace util { | 47 namespace util { |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 } | 162 } |
| 163 | 163 |
| 164 DriveServiceInterface* GetDriveServiceByProfile(Profile* profile) { | 164 DriveServiceInterface* GetDriveServiceByProfile(Profile* profile) { |
| 165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 166 | 166 |
| 167 DriveIntegrationService* integration_service = | 167 DriveIntegrationService* integration_service = |
| 168 GetIntegrationServiceByProfile(profile); | 168 GetIntegrationServiceByProfile(profile); |
| 169 return integration_service ? integration_service->drive_service() : NULL; | 169 return integration_service ? integration_service->drive_service() : NULL; |
| 170 } | 170 } |
| 171 | 171 |
| 172 GURL FilePathToDriveURL(const base::FilePath& path) { | |
| 173 std::string url(base::StringPrintf("%s:%s", | |
| 174 chrome::kDriveScheme, | |
| 175 path.AsUTF8Unsafe().c_str())); | |
| 176 return GURL(url); | |
| 177 } | |
| 178 | |
| 179 base::FilePath DriveURLToFilePath(const GURL& url) { | |
| 180 if (!url.is_valid() || url.scheme() != chrome::kDriveScheme) | |
| 181 return base::FilePath(); | |
| 182 std::string path_string = net::UnescapeURLComponent( | |
| 183 url.GetContent(), net::UnescapeRule::NORMAL); | |
| 184 return base::FilePath::FromUTF8Unsafe(path_string); | |
| 185 } | |
| 186 | |
| 187 void MaybeSetDriveURL(Profile* profile, const base::FilePath& path, GURL* url) { | |
| 188 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 189 | |
| 190 if (!IsUnderDriveMountPoint(path)) | |
| 191 return; | |
| 192 | |
| 193 FileSystemInterface* file_system = GetFileSystemByProfile(profile); | |
| 194 if (!file_system) | |
| 195 return; | |
| 196 | |
| 197 *url = FilePathToDriveURL(util::ExtractDrivePath(path)); | |
| 198 } | |
| 199 | |
| 200 bool IsUnderDriveMountPoint(const base::FilePath& path) { | 172 bool IsUnderDriveMountPoint(const base::FilePath& path) { |
| 201 return !ExtractDrivePath(path).empty(); | 173 return !ExtractDrivePath(path).empty(); |
| 202 } | 174 } |
| 203 | 175 |
| 204 base::FilePath ExtractDrivePath(const base::FilePath& path) { | 176 base::FilePath ExtractDrivePath(const base::FilePath& path) { |
| 205 std::vector<base::FilePath::StringType> components; | 177 std::vector<base::FilePath::StringType> components; |
| 206 path.GetComponents(&components); | 178 path.GetComponents(&components); |
| 207 if (components.size() < 3) | 179 if (components.size() < 3) |
| 208 return base::FilePath(); | 180 return base::FilePath(); |
| 209 if (components[0] != FILE_PATH_LITERAL("/")) | 181 if (components[0] != FILE_PATH_LITERAL("/")) |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 | 273 |
| 302 FileSystemInterface* file_system = GetFileSystemByProfile(profile); | 274 FileSystemInterface* file_system = GetFileSystemByProfile(profile); |
| 303 if (!file_system || !IsUnderDriveMountPoint(path)) { | 275 if (!file_system || !IsUnderDriveMountPoint(path)) { |
| 304 content::BrowserThread::GetBlockingPool()->PostTask( | 276 content::BrowserThread::GetBlockingPool()->PostTask( |
| 305 FROM_HERE, base::Bind(callback, FILE_ERROR_FAILED, base::FilePath())); | 277 FROM_HERE, base::Bind(callback, FILE_ERROR_FAILED, base::FilePath())); |
| 306 return; | 278 return; |
| 307 } | 279 } |
| 308 | 280 |
| 309 WriteOnCacheFile(file_system, | 281 WriteOnCacheFile(file_system, |
| 310 ExtractDrivePath(path), | 282 ExtractDrivePath(path), |
| 311 std::string(), // mime_type | 283 std::string(), // mime_type |
| 312 callback); | 284 callback); |
| 313 } | 285 } |
| 314 | 286 |
| 315 void EnsureDirectoryExists(Profile* profile, | 287 void EnsureDirectoryExists(Profile* profile, |
| 316 const base::FilePath& directory, | 288 const base::FilePath& directory, |
| 317 const FileOperationCallback& callback) { | 289 const FileOperationCallback& callback) { |
| 318 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 290 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 319 DCHECK(!callback.is_null()); | 291 DCHECK(!callback.is_null()); |
| 320 if (IsUnderDriveMountPoint(directory)) { | 292 if (IsUnderDriveMountPoint(directory)) { |
| 321 FileSystemInterface* file_system = GetFileSystemByProfile(profile); | 293 FileSystemInterface* file_system = GetFileSystemByProfile(profile); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 const bool disable_sync_over_celluar = | 355 const bool disable_sync_over_celluar = |
| 384 profile->GetPrefs()->GetBoolean(prefs::kDisableDriveOverCellular); | 356 profile->GetPrefs()->GetBoolean(prefs::kDisableDriveOverCellular); |
| 385 | 357 |
| 386 if (is_connection_cellular && disable_sync_over_celluar) | 358 if (is_connection_cellular && disable_sync_over_celluar) |
| 387 return DRIVE_CONNECTED_METERED; | 359 return DRIVE_CONNECTED_METERED; |
| 388 return DRIVE_CONNECTED; | 360 return DRIVE_CONNECTED; |
| 389 } | 361 } |
| 390 | 362 |
| 391 } // namespace util | 363 } // namespace util |
| 392 } // namespace drive | 364 } // namespace drive |
| OLD | NEW |