| Index: chrome/browser/chromeos/drive/file_system_core_util.cc
|
| diff --git a/chrome/browser/chromeos/drive/file_system_util.cc b/chrome/browser/chromeos/drive/file_system_core_util.cc
|
| similarity index 41%
|
| copy from chrome/browser/chromeos/drive/file_system_util.cc
|
| copy to chrome/browser/chromeos/drive/file_system_core_util.cc
|
| index d339124e74290ebff3e33bfb71665f682fd583d2..a8bb725333fc7bb68af35f4e6043d34063109447 100644
|
| --- a/chrome/browser/chromeos/drive/file_system_util.cc
|
| +++ b/chrome/browser/chromeos/drive/file_system_core_util.cc
|
| @@ -1,8 +1,8 @@
|
| -// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "chrome/browser/chromeos/drive/file_system_util.h"
|
| +#include "chrome/browser/chromeos/drive/file_system_core_util.h"
|
|
|
| #include <string>
|
| #include <vector>
|
| @@ -22,27 +22,12 @@
|
| #include "base/strings/stringprintf.h"
|
| #include "base/thread_task_runner_handle.h"
|
| #include "base/threading/sequenced_worker_pool.h"
|
| -#include "chrome/browser/browser_process.h"
|
| #include "chrome/browser/chromeos/drive/drive.pb.h"
|
| -#include "chrome/browser/chromeos/drive/drive_integration_service.h"
|
| #include "chrome/browser/chromeos/drive/drive_pref_names.h"
|
| #include "chrome/browser/chromeos/drive/file_system_interface.h"
|
| #include "chrome/browser/chromeos/drive/job_list.h"
|
| #include "chrome/browser/chromeos/drive/write_on_cache_file.h"
|
| -#include "chrome/browser/chromeos/profiles/profile_helper.h"
|
| -#include "chrome/browser/chromeos/profiles/profile_util.h"
|
| -#include "chrome/browser/profiles/profile.h"
|
| -#include "chrome/browser/profiles/profile_manager.h"
|
| -#include "chrome/common/chrome_constants.h"
|
| -#include "chrome/common/chrome_paths_internal.h"
|
| -#include "chrome/common/pref_names.h"
|
| -#include "chromeos/chromeos_constants.h"
|
| -#include "components/user_manager/user_manager.h"
|
| -#include "content/public/browser/browser_thread.h"
|
| #include "net/base/escape.h"
|
| -#include "storage/browser/fileapi/file_system_url.h"
|
| -
|
| -using content::BrowserThread;
|
|
|
| namespace drive {
|
| namespace util {
|
| @@ -53,8 +38,7 @@ std::string ReadStringFromGDocFile(const base::FilePath& file_path,
|
| const std::string& key) {
|
| const int64 kMaxGDocSize = 4096;
|
| int64 file_size = 0;
|
| - if (!base::GetFileSize(file_path, &file_size) ||
|
| - file_size > kMaxGDocSize) {
|
| + if (!base::GetFileSize(file_path, &file_size) || file_size > kMaxGDocSize) {
|
| LOG(WARNING) << "File too large to be a GDoc file " << file_path.value();
|
| return std::string();
|
| }
|
| @@ -80,16 +64,6 @@ std::string ReadStringFromGDocFile(const base::FilePath& file_path,
|
| return result;
|
| }
|
|
|
| -// Returns DriveIntegrationService instance, if Drive is enabled.
|
| -// Otherwise, NULL.
|
| -DriveIntegrationService* GetIntegrationServiceByProfile(Profile* profile) {
|
| - DriveIntegrationService* service =
|
| - DriveIntegrationServiceFactory::FindForProfile(profile);
|
| - if (!service || !service->IsMounted())
|
| - return NULL;
|
| - return service;
|
| -}
|
| -
|
| } // namespace
|
|
|
| const base::FilePath& GetDriveGrandRootPath() {
|
| @@ -111,65 +85,11 @@ base::FilePath GetDriveMountPointPathForUserIdHash(
|
| static const base::FilePath::CharType kSpecialMountPointRoot[] =
|
| FILE_PATH_LITERAL("/special");
|
| static const char kDriveMountPointNameBase[] = "drive";
|
| - return base::FilePath(kSpecialMountPointRoot).AppendASCII(
|
| - net::EscapeQueryParamValue(
|
| + return base::FilePath(kSpecialMountPointRoot)
|
| + .AppendASCII(net::EscapeQueryParamValue(
|
| kDriveMountPointNameBase +
|
| - (user_id_hash.empty() ? "" : "-" + user_id_hash), false));
|
| -}
|
| -
|
| -base::FilePath GetDriveMountPointPath(Profile* profile) {
|
| - std::string id = chromeos::ProfileHelper::GetUserIdHashFromProfile(profile);
|
| - if (id.empty() || id == chrome::kLegacyProfileDir) {
|
| - // ProfileHelper::GetUserIdHashFromProfile works only when multi-profile is
|
| - // enabled. In that case, we fall back to use UserManager (it basically just
|
| - // returns currently active users's hash in such a case.) I still try
|
| - // ProfileHelper first because it works better in tests.
|
| - const user_manager::User* const user =
|
| - user_manager::UserManager::IsInitialized()
|
| - ? chromeos::ProfileHelper::Get()->GetUserByProfile(
|
| - profile->GetOriginalProfile())
|
| - : NULL;
|
| - if (user)
|
| - id = user->username_hash();
|
| - }
|
| - return GetDriveMountPointPathForUserIdHash(id);
|
| -}
|
| -
|
| -FileSystemInterface* GetFileSystemByProfile(Profile* profile) {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| -
|
| - DriveIntegrationService* integration_service =
|
| - GetIntegrationServiceByProfile(profile);
|
| - return integration_service ? integration_service->file_system() : NULL;
|
| -}
|
| -
|
| -FileSystemInterface* GetFileSystemByProfileId(void* profile_id) {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| -
|
| - // |profile_id| needs to be checked with ProfileManager::IsValidProfile
|
| - // before using it.
|
| - Profile* profile = reinterpret_cast<Profile*>(profile_id);
|
| - if (!g_browser_process->profile_manager()->IsValidProfile(profile))
|
| - return NULL;
|
| - return GetFileSystemByProfile(profile);
|
| -}
|
| -
|
| -DriveAppRegistry* GetDriveAppRegistryByProfile(Profile* profile) {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| -
|
| - DriveIntegrationService* integration_service =
|
| - GetIntegrationServiceByProfile(profile);
|
| - return integration_service ?
|
| - integration_service->drive_app_registry() :
|
| - NULL;
|
| -}
|
| -
|
| -DriveServiceInterface* GetDriveServiceByProfile(Profile* profile) {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| -
|
| - DriveIntegrationService* integration_service =
|
| - GetIntegrationServiceByProfile(profile);
|
| - return integration_service ? integration_service->drive_service() : NULL;
|
| + (user_id_hash.empty() ? "" : "-" + user_id_hash),
|
| + false));
|
| }
|
|
|
| bool IsUnderDriveMountPoint(const base::FilePath& path) {
|
| @@ -195,40 +115,6 @@ base::FilePath ExtractDrivePath(const base::FilePath& path) {
|
| return drive_path;
|
| }
|
|
|
| -Profile* ExtractProfileFromPath(const base::FilePath& path) {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| -
|
| - const std::vector<Profile*>& profiles =
|
| - g_browser_process->profile_manager()->GetLoadedProfiles();
|
| - for (size_t i = 0; i < profiles.size(); ++i) {
|
| - Profile* original_profile = profiles[i]->GetOriginalProfile();
|
| - if (original_profile == profiles[i] &&
|
| - !chromeos::ProfileHelper::IsSigninProfile(original_profile)) {
|
| - const base::FilePath base = GetDriveMountPointPath(original_profile);
|
| - if (base == path || base.IsParent(path))
|
| - return original_profile;
|
| - }
|
| - }
|
| - return NULL;
|
| -}
|
| -
|
| -base::FilePath ExtractDrivePathFromFileSystemUrl(
|
| - const storage::FileSystemURL& url) {
|
| - if (!url.is_valid() || url.type() != storage::kFileSystemTypeDrive)
|
| - return base::FilePath();
|
| - return ExtractDrivePath(url.path());
|
| -}
|
| -
|
| -base::FilePath GetCacheRootPath(Profile* profile) {
|
| - base::FilePath cache_base_path;
|
| - chrome::GetUserCacheDirectory(profile->GetPath(), &cache_base_path);
|
| - base::FilePath cache_root_path =
|
| - cache_base_path.Append(chromeos::kDriveCacheDirname);
|
| - static const base::FilePath::CharType kFileCacheVersionDir[] =
|
| - FILE_PATH_LITERAL("v1");
|
| - return cache_root_path.Append(kFileCacheVersionDir);
|
| -}
|
| -
|
| std::string EscapeCacheFileName(const std::string& filename) {
|
| // This is based on net/base/escape.cc: net::(anonymous namespace)::Escape
|
| std::string escaped;
|
| @@ -249,7 +135,7 @@ std::string UnescapeCacheFileName(const std::string& filename) {
|
| char c = filename[i];
|
| if (c == '%' && i + 2 < filename.length()) {
|
| c = (HexDigitToInt(filename[i + 1]) << 4) +
|
| - HexDigitToInt(filename[i + 2]);
|
| + HexDigitToInt(filename[i + 2]);
|
| i += 2;
|
| }
|
| unescaped.push_back(c);
|
| @@ -269,55 +155,17 @@ std::string NormalizeFileName(const std::string& input) {
|
| return output;
|
| }
|
|
|
| -void PrepareWritableFileAndRun(Profile* profile,
|
| - const base::FilePath& path,
|
| - const PrepareWritableFileCallback& callback) {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| - DCHECK(!callback.is_null());
|
| -
|
| - FileSystemInterface* file_system = GetFileSystemByProfile(profile);
|
| - if (!file_system || !IsUnderDriveMountPoint(path)) {
|
| - content::BrowserThread::GetBlockingPool()->PostTask(
|
| - FROM_HERE, base::Bind(callback, FILE_ERROR_FAILED, base::FilePath()));
|
| - return;
|
| - }
|
| -
|
| - WriteOnCacheFile(file_system,
|
| - ExtractDrivePath(path),
|
| - std::string(), // mime_type
|
| - callback);
|
| -}
|
| -
|
| -void EnsureDirectoryExists(Profile* profile,
|
| - const base::FilePath& directory,
|
| - const FileOperationCallback& callback) {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| - DCHECK(!callback.is_null());
|
| - if (IsUnderDriveMountPoint(directory)) {
|
| - FileSystemInterface* file_system = GetFileSystemByProfile(profile);
|
| - DCHECK(file_system);
|
| - file_system->CreateDirectory(
|
| - ExtractDrivePath(directory),
|
| - true /* is_exclusive */,
|
| - true /* is_recursive */,
|
| - callback);
|
| - } else {
|
| - base::ThreadTaskRunnerHandle::Get()->PostTask(
|
| - FROM_HERE, base::Bind(callback, FILE_ERROR_OK));
|
| - }
|
| -}
|
| -
|
| void EmptyFileOperationCallback(FileError error) {
|
| }
|
|
|
| bool CreateGDocFile(const base::FilePath& file_path,
|
| const GURL& url,
|
| const std::string& resource_id) {
|
| - std::string content = base::StringPrintf(
|
| - "{\"url\": \"%s\", \"resource_id\": \"%s\"}",
|
| - url.spec().c_str(), resource_id.c_str());
|
| + std::string content =
|
| + base::StringPrintf("{\"url\": \"%s\", \"resource_id\": \"%s\"}",
|
| + url.spec().c_str(), resource_id.c_str());
|
| return base::WriteFile(file_path, content.data(), content.size()) ==
|
| - static_cast<int>(content.size());
|
| + static_cast<int>(content.size());
|
| }
|
|
|
| GURL ReadUrlFromGDocFile(const base::FilePath& file_path) {
|
| @@ -328,41 +176,5 @@ std::string ReadResourceIdFromGDocFile(const base::FilePath& file_path) {
|
| return ReadStringFromGDocFile(file_path, "resource_id");
|
| }
|
|
|
| -bool IsDriveEnabledForProfile(Profile* profile) {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| -
|
| - if (!chromeos::IsProfileAssociatedWithGaiaAccount(profile))
|
| - return false;
|
| -
|
| - // Disable Drive if preference is set. This can happen with commandline flag
|
| - // --disable-drive or enterprise policy, or with user settings.
|
| - if (profile->GetPrefs()->GetBoolean(prefs::kDisableDrive))
|
| - return false;
|
| -
|
| - return true;
|
| -}
|
| -
|
| -ConnectionStatusType GetDriveConnectionStatus(Profile* profile) {
|
| - drive::DriveServiceInterface* const drive_service =
|
| - drive::util::GetDriveServiceByProfile(profile);
|
| -
|
| - if (!drive_service)
|
| - return DRIVE_DISCONNECTED_NOSERVICE;
|
| - if (net::NetworkChangeNotifier::IsOffline())
|
| - return DRIVE_DISCONNECTED_NONETWORK;
|
| - if (!drive_service->CanSendRequest())
|
| - return DRIVE_DISCONNECTED_NOTREADY;
|
| -
|
| - const bool is_connection_cellular =
|
| - net::NetworkChangeNotifier::IsConnectionCellular(
|
| - net::NetworkChangeNotifier::GetConnectionType());
|
| - const bool disable_sync_over_celluar =
|
| - profile->GetPrefs()->GetBoolean(prefs::kDisableDriveOverCellular);
|
| -
|
| - if (is_connection_cellular && disable_sync_over_celluar)
|
| - return DRIVE_CONNECTED_METERED;
|
| - return DRIVE_CONNECTED;
|
| -}
|
| -
|
| } // namespace util
|
| } // namespace drive
|
|
|