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

Side by Side Diff: chrome/browser/chromeos/drive/file_system_util.cc

Issue 1296483003: Move chrome/browser/chromeos/drive/resource* (+deps) into components/drive. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebasing... Created 5 years, 4 months 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
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/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 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/files/file_util.h" 14 #include "base/files/file_util.h"
15 #include "base/i18n/icu_string_conversions.h" 15 #include "base/i18n/icu_string_conversions.h"
16 #include "base/json/json_file_value_serializer.h" 16 #include "base/json/json_file_value_serializer.h"
17 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/memory/scoped_ptr.h" 18 #include "base/memory/scoped_ptr.h"
19 #include "base/prefs/pref_service.h" 19 #include "base/prefs/pref_service.h"
20 #include "base/strings/string_number_conversions.h" 20 #include "base/strings/string_number_conversions.h"
21 #include "base/strings/string_util.h" 21 #include "base/strings/string_util.h"
22 #include "base/strings/stringprintf.h" 22 #include "base/strings/stringprintf.h"
23 #include "base/thread_task_runner_handle.h" 23 #include "base/thread_task_runner_handle.h"
24 #include "base/threading/sequenced_worker_pool.h" 24 #include "base/threading/sequenced_worker_pool.h"
25 #include "chrome/browser/browser_process.h" 25 #include "chrome/browser/browser_process.h"
26 #include "chrome/browser/chromeos/drive/drive_integration_service.h" 26 #include "chrome/browser/chromeos/drive/drive_integration_service.h"
27 #include "chrome/browser/chromeos/drive/file_system_core_util.h"
28 #include "chrome/browser/chromeos/drive/file_system_interface.h" 27 #include "chrome/browser/chromeos/drive/file_system_interface.h"
29 #include "chrome/browser/chromeos/drive/write_on_cache_file.h" 28 #include "chrome/browser/chromeos/drive/write_on_cache_file.h"
30 #include "chrome/browser/chromeos/profiles/profile_helper.h" 29 #include "chrome/browser/chromeos/profiles/profile_helper.h"
31 #include "chrome/browser/chromeos/profiles/profile_util.h" 30 #include "chrome/browser/chromeos/profiles/profile_util.h"
32 #include "chrome/browser/profiles/profile.h" 31 #include "chrome/browser/profiles/profile.h"
33 #include "chrome/browser/profiles/profile_manager.h" 32 #include "chrome/browser/profiles/profile_manager.h"
34 #include "chrome/common/chrome_constants.h" 33 #include "chrome/common/chrome_constants.h"
35 #include "chrome/common/chrome_paths_internal.h" 34 #include "chrome/common/chrome_paths_internal.h"
36 #include "chromeos/chromeos_constants.h" 35 #include "chromeos/chromeos_constants.h"
37 #include "components/drive/drive.pb.h" 36 #include "components/drive/drive.pb.h"
38 #include "components/drive/drive_pref_names.h" 37 #include "components/drive/drive_pref_names.h"
38 #include "components/drive/file_system_core_util.h"
39 #include "components/drive/job_list.h" 39 #include "components/drive/job_list.h"
40 #include "components/user_manager/user_manager.h" 40 #include "components/user_manager/user_manager.h"
41 #include "content/public/browser/browser_thread.h" 41 #include "content/public/browser/browser_thread.h"
42 #include "net/base/escape.h"
42 #include "storage/browser/fileapi/file_system_url.h" 43 #include "storage/browser/fileapi/file_system_url.h"
43 44
44 using content::BrowserThread; 45 using content::BrowserThread;
45 46
46 namespace drive { 47 namespace drive {
47 namespace util { 48 namespace util {
48 49
49 namespace { 50 namespace {
50 51
51 // Returns DriveIntegrationService instance, if Drive is enabled. 52 // Returns DriveIntegrationService instance, if Drive is enabled.
(...skipping 19 matching lines...) Expand all
71 user_manager::UserManager::IsInitialized() 72 user_manager::UserManager::IsInitialized()
72 ? chromeos::ProfileHelper::Get()->GetUserByProfile( 73 ? chromeos::ProfileHelper::Get()->GetUserByProfile(
73 profile->GetOriginalProfile()) 74 profile->GetOriginalProfile())
74 : NULL; 75 : NULL;
75 if (user) 76 if (user)
76 id = user->username_hash(); 77 id = user->username_hash();
77 } 78 }
78 return GetDriveMountPointPathForUserIdHash(id); 79 return GetDriveMountPointPathForUserIdHash(id);
79 } 80 }
80 81
82 base::FilePath GetDriveMountPointPathForUserIdHash(
83 const std::string user_id_hash) {
84 static const base::FilePath::CharType kSpecialMountPointRoot[] =
85 FILE_PATH_LITERAL("/special");
86 static const char kDriveMountPointNameBase[] = "drive";
87 return base::FilePath(kSpecialMountPointRoot)
88 .AppendASCII(net::EscapeQueryParamValue(
89 kDriveMountPointNameBase +
90 (user_id_hash.empty() ? "" : "-" + user_id_hash),
91 false));
92 }
93
94 bool IsUnderDriveMountPoint(const base::FilePath& path) {
95 return !ExtractDrivePath(path).empty();
96 }
97
98 base::FilePath ExtractDrivePath(const base::FilePath& path) {
99 std::vector<base::FilePath::StringType> components;
100 path.GetComponents(&components);
101 if (components.size() < 3)
102 return base::FilePath();
103 if (components[0] != FILE_PATH_LITERAL("/"))
104 return base::FilePath();
105 if (components[1] != FILE_PATH_LITERAL("special"))
106 return base::FilePath();
107 static const base::FilePath::CharType kPrefix[] = FILE_PATH_LITERAL("drive");
108 if (components[2].compare(0, arraysize(kPrefix) - 1, kPrefix) != 0)
109 return base::FilePath();
110
111 base::FilePath drive_path = GetDriveGrandRootPath();
112 for (size_t i = 3; i < components.size(); ++i)
113 drive_path = drive_path.Append(components[i]);
114 return drive_path;
115 }
116
81 FileSystemInterface* GetFileSystemByProfile(Profile* profile) { 117 FileSystemInterface* GetFileSystemByProfile(Profile* profile) {
82 DCHECK_CURRENTLY_ON(BrowserThread::UI); 118 DCHECK_CURRENTLY_ON(BrowserThread::UI);
83 119
84 DriveIntegrationService* integration_service = 120 DriveIntegrationService* integration_service =
85 GetIntegrationServiceByProfile(profile); 121 GetIntegrationServiceByProfile(profile);
86 return integration_service ? integration_service->file_system() : NULL; 122 return integration_service ? integration_service->file_system() : NULL;
87 } 123 }
88 124
89 FileSystemInterface* GetFileSystemByProfileId(void* profile_id) { 125 FileSystemInterface* GetFileSystemByProfileId(void* profile_id) {
90 DCHECK_CURRENTLY_ON(BrowserThread::UI); 126 DCHECK_CURRENTLY_ON(BrowserThread::UI);
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 const bool disable_sync_over_celluar = 249 const bool disable_sync_over_celluar =
214 profile->GetPrefs()->GetBoolean(prefs::kDisableDriveOverCellular); 250 profile->GetPrefs()->GetBoolean(prefs::kDisableDriveOverCellular);
215 251
216 if (is_connection_cellular && disable_sync_over_celluar) 252 if (is_connection_cellular && disable_sync_over_celluar)
217 return DRIVE_CONNECTED_METERED; 253 return DRIVE_CONNECTED_METERED;
218 return DRIVE_CONNECTED; 254 return DRIVE_CONNECTED;
219 } 255 }
220 256
221 } // namespace util 257 } // namespace util
222 } // namespace drive 258 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/file_system_util.h ('k') | chrome/browser/chromeos/drive/file_system_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698