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

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

Issue 150163003: drive: Switch Drive mount path to per-profile one. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fix. Created 6 years, 10 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 | Annotate | Revision Log
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 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/i18n/icu_string_conversions.h" 14 #include "base/i18n/icu_string_conversions.h"
15 #include "base/json/json_file_value_serializer.h" 15 #include "base/json/json_file_value_serializer.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/memory/scoped_ptr.h" 17 #include "base/memory/scoped_ptr.h"
18 #include "base/message_loop/message_loop_proxy.h" 18 #include "base/message_loop/message_loop_proxy.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/threading/sequenced_worker_pool.h" 23 #include "base/threading/sequenced_worker_pool.h"
24 #include "chrome/browser/browser_process.h" 24 #include "chrome/browser/browser_process.h"
25 #include "chrome/browser/chromeos/drive/drive.pb.h" 25 #include "chrome/browser/chromeos/drive/drive.pb.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_interface.h" 27 #include "chrome/browser/chromeos/drive/file_system_interface.h"
28 #include "chrome/browser/chromeos/drive/job_list.h" 28 #include "chrome/browser/chromeos/drive/job_list.h"
29 #include "chrome/browser/chromeos/drive/write_on_cache_file.h" 29 #include "chrome/browser/chromeos/drive/write_on_cache_file.h"
30 #include "chrome/browser/chromeos/profiles/profile_helper.h"
30 #include "chrome/browser/chromeos/profiles/profile_util.h" 31 #include "chrome/browser/chromeos/profiles/profile_util.h"
31 #include "chrome/browser/profiles/profile.h" 32 #include "chrome/browser/profiles/profile.h"
32 #include "chrome/browser/profiles/profile_manager.h" 33 #include "chrome/browser/profiles/profile_manager.h"
33 #include "chrome/common/chrome_constants.h" 34 #include "chrome/common/chrome_constants.h"
34 #include "chrome/common/chrome_paths_internal.h" 35 #include "chrome/common/chrome_paths_internal.h"
35 #include "chrome/common/pref_names.h" 36 #include "chrome/common/pref_names.h"
36 #include "chrome/common/url_constants.h" 37 #include "chrome/common/url_constants.h"
37 #include "chromeos/chromeos_constants.h" 38 #include "chromeos/chromeos_constants.h"
38 #include "content/public/browser/browser_thread.h" 39 #include "content/public/browser/browser_thread.h"
39 #include "google_apis/drive/gdata_wapi_parser.h" 40 #include "google_apis/drive/gdata_wapi_parser.h"
40 #include "net/base/escape.h" 41 #include "net/base/escape.h"
41 #include "webkit/browser/fileapi/file_system_url.h" 42 #include "webkit/browser/fileapi/file_system_url.h"
42 43
43 using content::BrowserThread; 44 using content::BrowserThread;
44 45
45 namespace drive { 46 namespace drive {
46 namespace util { 47 namespace util {
47 48
48 namespace { 49 namespace {
49 50
50 const base::FilePath::CharType kDriveMountPointPath[] = 51 const base::FilePath::CharType kSpecialMountPointRoot[] =
51 FILE_PATH_LITERAL("/special/drive"); 52 FILE_PATH_LITERAL("/special");
53
54 const char kDriveMountPointNameBase[] = "drive";
52 55
53 const base::FilePath::CharType kDriveMyDriveRootPath[] = 56 const base::FilePath::CharType kDriveMyDriveRootPath[] =
54 FILE_PATH_LITERAL("drive/root"); 57 FILE_PATH_LITERAL("drive/root");
55 58
56 const base::FilePath::CharType kFileCacheVersionDir[] = 59 const base::FilePath::CharType kFileCacheVersionDir[] =
57 FILE_PATH_LITERAL("v1"); 60 FILE_PATH_LITERAL("v1");
58 61
59 const char kSlash[] = "/"; 62 const char kSlash[] = "/";
60 const char kDot = '.'; 63 const char kDot = '.';
61 const char kEscapedChars[] = "_"; 64 const char kEscapedChars[] = "_";
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 (kDriveGrandRootDirName)); 120 (kDriveGrandRootDirName));
118 return grand_root_path; 121 return grand_root_path;
119 } 122 }
120 123
121 const base::FilePath& GetDriveMyDriveRootPath() { 124 const base::FilePath& GetDriveMyDriveRootPath() {
122 CR_DEFINE_STATIC_LOCAL(base::FilePath, drive_root_path, 125 CR_DEFINE_STATIC_LOCAL(base::FilePath, drive_root_path,
123 (kDriveMyDriveRootPath)); 126 (kDriveMyDriveRootPath));
124 return drive_root_path; 127 return drive_root_path;
125 } 128 }
126 129
127 const base::FilePath& GetDriveMountPointPath(Profile* profile) { 130 base::FilePath GetDriveMountPointPath(Profile* profile) {
128 // TODO(kinaba): assign different path for each different profile. 131 const std::string id = "-" +
129 CR_DEFINE_STATIC_LOCAL(base::FilePath, drive_mount_path, 132 chromeos::ProfileHelper::GetUserIdHashFromProfile(profile);
130 (kDriveMountPointPath)); 133 return base::FilePath(kSpecialMountPointRoot).AppendASCII(
131 return drive_mount_path; 134 net::EscapePath(kDriveMountPointNameBase + id));
132 } 135 }
133 136
134 FileSystemInterface* GetFileSystemByProfile(Profile* profile) { 137 FileSystemInterface* GetFileSystemByProfile(Profile* profile) {
135 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 138 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
136 139
137 DriveIntegrationService* integration_service = 140 DriveIntegrationService* integration_service =
138 GetIntegrationServiceByProfile(profile); 141 GetIntegrationServiceByProfile(profile);
139 return integration_service ? integration_service->file_system() : NULL; 142 return integration_service ? integration_service->file_system() : NULL;
140 } 143 }
141 144
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 return base::FilePath(); 214 return base::FilePath();
212 if (!StartsWithASCII(components[2], "drive", true)) 215 if (!StartsWithASCII(components[2], "drive", true))
213 return base::FilePath(); 216 return base::FilePath();
214 217
215 base::FilePath drive_path = GetDriveGrandRootPath(); 218 base::FilePath drive_path = GetDriveGrandRootPath();
216 for (size_t i = 3; i < components.size(); ++i) 219 for (size_t i = 3; i < components.size(); ++i)
217 drive_path = drive_path.Append(components[i]); 220 drive_path = drive_path.Append(components[i]);
218 return drive_path; 221 return drive_path;
219 } 222 }
220 223
224 Profile* ExtractProfileFromPath(const base::FilePath& path) {
225 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
226
227 const std::vector<Profile*>& profiles =
228 g_browser_process->profile_manager()->GetLoadedProfiles();
229 for (size_t i = 0; i < profiles.size(); ++i) {
230 Profile* original_profile = profiles[i]->GetOriginalProfile();
231 if (original_profile == profiles[i]) {
232 const base::FilePath base = GetDriveMountPointPath(original_profile);
233 if (base == path || base.IsParent(path))
234 return original_profile;
235 }
236 }
237 return NULL;
238 }
239
221 base::FilePath ExtractDrivePathFromFileSystemUrl( 240 base::FilePath ExtractDrivePathFromFileSystemUrl(
222 const fileapi::FileSystemURL& url) { 241 const fileapi::FileSystemURL& url) {
223 if (!url.is_valid() || url.type() != fileapi::kFileSystemTypeDrive) 242 if (!url.is_valid() || url.type() != fileapi::kFileSystemTypeDrive)
224 return base::FilePath(); 243 return base::FilePath();
225 return ExtractDrivePath(url.path()); 244 return ExtractDrivePath(url.path());
226 } 245 }
227 246
228 base::FilePath GetCacheRootPath(Profile* profile) { 247 base::FilePath GetCacheRootPath(Profile* profile) {
229 base::FilePath cache_base_path; 248 base::FilePath cache_base_path;
230 chrome::GetUserCacheDirectory(profile->GetPath(), &cache_base_path); 249 chrome::GetUserCacheDirectory(profile->GetPath(), &cache_base_path);
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 const bool disable_sync_over_celluar = 402 const bool disable_sync_over_celluar =
384 profile->GetPrefs()->GetBoolean(prefs::kDisableDriveOverCellular); 403 profile->GetPrefs()->GetBoolean(prefs::kDisableDriveOverCellular);
385 404
386 if (is_connection_cellular && disable_sync_over_celluar) 405 if (is_connection_cellular && disable_sync_over_celluar)
387 return DRIVE_CONNECTED_METERED; 406 return DRIVE_CONNECTED_METERED;
388 return DRIVE_CONNECTED; 407 return DRIVE_CONNECTED;
389 } 408 }
390 409
391 } // namespace util 410 } // namespace util
392 } // namespace drive 411 } // 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