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

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

Issue 1036723003: favor DCHECK_CURRENTLY_ON for better logs in chrome/browser/chromeos/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 ? chromeos::ProfileHelper::Get()->GetUserByProfile( 126 ? chromeos::ProfileHelper::Get()->GetUserByProfile(
127 profile->GetOriginalProfile()) 127 profile->GetOriginalProfile())
128 : NULL; 128 : NULL;
129 if (user) 129 if (user)
130 id = user->username_hash(); 130 id = user->username_hash();
131 } 131 }
132 return GetDriveMountPointPathForUserIdHash(id); 132 return GetDriveMountPointPathForUserIdHash(id);
133 } 133 }
134 134
135 FileSystemInterface* GetFileSystemByProfile(Profile* profile) { 135 FileSystemInterface* GetFileSystemByProfile(Profile* profile) {
136 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 136 DCHECK_CURRENTLY_ON(BrowserThread::UI);
137 137
138 DriveIntegrationService* integration_service = 138 DriveIntegrationService* integration_service =
139 GetIntegrationServiceByProfile(profile); 139 GetIntegrationServiceByProfile(profile);
140 return integration_service ? integration_service->file_system() : NULL; 140 return integration_service ? integration_service->file_system() : NULL;
141 } 141 }
142 142
143 FileSystemInterface* GetFileSystemByProfileId(void* profile_id) { 143 FileSystemInterface* GetFileSystemByProfileId(void* profile_id) {
144 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 144 DCHECK_CURRENTLY_ON(BrowserThread::UI);
145 145
146 // |profile_id| needs to be checked with ProfileManager::IsValidProfile 146 // |profile_id| needs to be checked with ProfileManager::IsValidProfile
147 // before using it. 147 // before using it.
148 Profile* profile = reinterpret_cast<Profile*>(profile_id); 148 Profile* profile = reinterpret_cast<Profile*>(profile_id);
149 if (!g_browser_process->profile_manager()->IsValidProfile(profile)) 149 if (!g_browser_process->profile_manager()->IsValidProfile(profile))
150 return NULL; 150 return NULL;
151 return GetFileSystemByProfile(profile); 151 return GetFileSystemByProfile(profile);
152 } 152 }
153 153
154 DriveAppRegistry* GetDriveAppRegistryByProfile(Profile* profile) { 154 DriveAppRegistry* GetDriveAppRegistryByProfile(Profile* profile) {
155 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 155 DCHECK_CURRENTLY_ON(BrowserThread::UI);
156 156
157 DriveIntegrationService* integration_service = 157 DriveIntegrationService* integration_service =
158 GetIntegrationServiceByProfile(profile); 158 GetIntegrationServiceByProfile(profile);
159 return integration_service ? 159 return integration_service ?
160 integration_service->drive_app_registry() : 160 integration_service->drive_app_registry() :
161 NULL; 161 NULL;
162 } 162 }
163 163
164 DriveServiceInterface* GetDriveServiceByProfile(Profile* profile) { 164 DriveServiceInterface* GetDriveServiceByProfile(Profile* profile) {
165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 165 DCHECK_CURRENTLY_ON(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 bool IsUnderDriveMountPoint(const base::FilePath& path) { 172 bool IsUnderDriveMountPoint(const base::FilePath& path) {
173 return !ExtractDrivePath(path).empty(); 173 return !ExtractDrivePath(path).empty();
174 } 174 }
175 175
176 base::FilePath ExtractDrivePath(const base::FilePath& path) { 176 base::FilePath ExtractDrivePath(const base::FilePath& path) {
177 std::vector<base::FilePath::StringType> components; 177 std::vector<base::FilePath::StringType> components;
178 path.GetComponents(&components); 178 path.GetComponents(&components);
179 if (components.size() < 3) 179 if (components.size() < 3)
180 return base::FilePath(); 180 return base::FilePath();
181 if (components[0] != FILE_PATH_LITERAL("/")) 181 if (components[0] != FILE_PATH_LITERAL("/"))
182 return base::FilePath(); 182 return base::FilePath();
183 if (components[1] != FILE_PATH_LITERAL("special")) 183 if (components[1] != FILE_PATH_LITERAL("special"))
184 return base::FilePath(); 184 return base::FilePath();
185 if (!StartsWithASCII(components[2], "drive", true)) 185 if (!StartsWithASCII(components[2], "drive", true))
186 return base::FilePath(); 186 return base::FilePath();
187 187
188 base::FilePath drive_path = GetDriveGrandRootPath(); 188 base::FilePath drive_path = GetDriveGrandRootPath();
189 for (size_t i = 3; i < components.size(); ++i) 189 for (size_t i = 3; i < components.size(); ++i)
190 drive_path = drive_path.Append(components[i]); 190 drive_path = drive_path.Append(components[i]);
191 return drive_path; 191 return drive_path;
192 } 192 }
193 193
194 Profile* ExtractProfileFromPath(const base::FilePath& path) { 194 Profile* ExtractProfileFromPath(const base::FilePath& path) {
195 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 195 DCHECK_CURRENTLY_ON(BrowserThread::UI);
196 196
197 const std::vector<Profile*>& profiles = 197 const std::vector<Profile*>& profiles =
198 g_browser_process->profile_manager()->GetLoadedProfiles(); 198 g_browser_process->profile_manager()->GetLoadedProfiles();
199 for (size_t i = 0; i < profiles.size(); ++i) { 199 for (size_t i = 0; i < profiles.size(); ++i) {
200 Profile* original_profile = profiles[i]->GetOriginalProfile(); 200 Profile* original_profile = profiles[i]->GetOriginalProfile();
201 if (original_profile == profiles[i] && 201 if (original_profile == profiles[i] &&
202 !chromeos::ProfileHelper::IsSigninProfile(original_profile)) { 202 !chromeos::ProfileHelper::IsSigninProfile(original_profile)) {
203 const base::FilePath base = GetDriveMountPointPath(original_profile); 203 const base::FilePath base = GetDriveMountPointPath(original_profile);
204 if (base == path || base.IsParent(path)) 204 if (base == path || base.IsParent(path))
205 return original_profile; 205 return original_profile;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 output = input; 261 output = input;
262 base::ReplaceChars(output, "/", "_", &output); 262 base::ReplaceChars(output, "/", "_", &output);
263 if (!output.empty() && output.find_first_not_of('.', 0) == std::string::npos) 263 if (!output.empty() && output.find_first_not_of('.', 0) == std::string::npos)
264 output = "_"; 264 output = "_";
265 return output; 265 return output;
266 } 266 }
267 267
268 void PrepareWritableFileAndRun(Profile* profile, 268 void PrepareWritableFileAndRun(Profile* profile,
269 const base::FilePath& path, 269 const base::FilePath& path,
270 const PrepareWritableFileCallback& callback) { 270 const PrepareWritableFileCallback& callback) {
271 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 271 DCHECK_CURRENTLY_ON(BrowserThread::UI);
272 DCHECK(!callback.is_null()); 272 DCHECK(!callback.is_null());
273 273
274 FileSystemInterface* file_system = GetFileSystemByProfile(profile); 274 FileSystemInterface* file_system = GetFileSystemByProfile(profile);
275 if (!file_system || !IsUnderDriveMountPoint(path)) { 275 if (!file_system || !IsUnderDriveMountPoint(path)) {
276 content::BrowserThread::GetBlockingPool()->PostTask( 276 content::BrowserThread::GetBlockingPool()->PostTask(
277 FROM_HERE, base::Bind(callback, FILE_ERROR_FAILED, base::FilePath())); 277 FROM_HERE, base::Bind(callback, FILE_ERROR_FAILED, base::FilePath()));
278 return; 278 return;
279 } 279 }
280 280
281 WriteOnCacheFile(file_system, 281 WriteOnCacheFile(file_system,
282 ExtractDrivePath(path), 282 ExtractDrivePath(path),
283 std::string(), // mime_type 283 std::string(), // mime_type
284 callback); 284 callback);
285 } 285 }
286 286
287 void EnsureDirectoryExists(Profile* profile, 287 void EnsureDirectoryExists(Profile* profile,
288 const base::FilePath& directory, 288 const base::FilePath& directory,
289 const FileOperationCallback& callback) { 289 const FileOperationCallback& callback) {
290 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 290 DCHECK_CURRENTLY_ON(BrowserThread::UI);
291 DCHECK(!callback.is_null()); 291 DCHECK(!callback.is_null());
292 if (IsUnderDriveMountPoint(directory)) { 292 if (IsUnderDriveMountPoint(directory)) {
293 FileSystemInterface* file_system = GetFileSystemByProfile(profile); 293 FileSystemInterface* file_system = GetFileSystemByProfile(profile);
294 DCHECK(file_system); 294 DCHECK(file_system);
295 file_system->CreateDirectory( 295 file_system->CreateDirectory(
296 ExtractDrivePath(directory), 296 ExtractDrivePath(directory),
297 true /* is_exclusive */, 297 true /* is_exclusive */,
298 true /* is_recursive */, 298 true /* is_recursive */,
299 callback); 299 callback);
300 } else { 300 } else {
(...skipping 17 matching lines...) Expand all
318 318
319 GURL ReadUrlFromGDocFile(const base::FilePath& file_path) { 319 GURL ReadUrlFromGDocFile(const base::FilePath& file_path) {
320 return GURL(ReadStringFromGDocFile(file_path, "url")); 320 return GURL(ReadStringFromGDocFile(file_path, "url"));
321 } 321 }
322 322
323 std::string ReadResourceIdFromGDocFile(const base::FilePath& file_path) { 323 std::string ReadResourceIdFromGDocFile(const base::FilePath& file_path) {
324 return ReadStringFromGDocFile(file_path, "resource_id"); 324 return ReadStringFromGDocFile(file_path, "resource_id");
325 } 325 }
326 326
327 bool IsDriveEnabledForProfile(Profile* profile) { 327 bool IsDriveEnabledForProfile(Profile* profile) {
328 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 328 DCHECK_CURRENTLY_ON(BrowserThread::UI);
329 329
330 if (!chromeos::IsProfileAssociatedWithGaiaAccount(profile)) 330 if (!chromeos::IsProfileAssociatedWithGaiaAccount(profile))
331 return false; 331 return false;
332 332
333 // Disable Drive if preference is set. This can happen with commandline flag 333 // Disable Drive if preference is set. This can happen with commandline flag
334 // --disable-drive or enterprise policy, or with user settings. 334 // --disable-drive or enterprise policy, or with user settings.
335 if (profile->GetPrefs()->GetBoolean(prefs::kDisableDrive)) 335 if (profile->GetPrefs()->GetBoolean(prefs::kDisableDrive))
336 return false; 336 return false;
337 337
338 return true; 338 return true;
(...skipping 16 matching lines...) Expand all
355 const bool disable_sync_over_celluar = 355 const bool disable_sync_over_celluar =
356 profile->GetPrefs()->GetBoolean(prefs::kDisableDriveOverCellular); 356 profile->GetPrefs()->GetBoolean(prefs::kDisableDriveOverCellular);
357 357
358 if (is_connection_cellular && disable_sync_over_celluar) 358 if (is_connection_cellular && disable_sync_over_celluar)
359 return DRIVE_CONNECTED_METERED; 359 return DRIVE_CONNECTED_METERED;
360 return DRIVE_CONNECTED; 360 return DRIVE_CONNECTED;
361 } 361 }
362 362
363 } // namespace util 363 } // namespace util
364 } // namespace drive 364 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/file_system/truncate_operation.cc ('k') | chrome/browser/chromeos/drive/file_write_watcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698