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

Side by Side Diff: components/drive/file_system_core_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: 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_core_util.h" 5 #include "components/drive/file_system_core_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/chromeos/drive/file_system_interface.h"
26 #include "chrome/browser/chromeos/drive/write_on_cache_file.h"
27 #include "components/drive/drive.pb.h" 25 #include "components/drive/drive.pb.h"
28 #include "components/drive/drive_pref_names.h" 26 #include "components/drive/drive_pref_names.h"
29 #include "components/drive/job_list.h" 27 #include "components/drive/job_list.h"
30 #include "net/base/escape.h"
31 28
32 namespace drive { 29 namespace drive {
33 namespace util { 30 namespace util {
34 31
35 namespace { 32 namespace {
36 33
37 std::string ReadStringFromGDocFile(const base::FilePath& file_path, 34 std::string ReadStringFromGDocFile(const base::FilePath& file_path,
38 const std::string& key) { 35 const std::string& key) {
39 const int64 kMaxGDocSize = 4096; 36 const int64 kMaxGDocSize = 4096;
40 int64 file_size = 0; 37 int64 file_size = 0;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 return grand_root_path; 70 return grand_root_path;
74 } 71 }
75 72
76 const base::FilePath& GetDriveMyDriveRootPath() { 73 const base::FilePath& GetDriveMyDriveRootPath() {
77 CR_DEFINE_STATIC_LOCAL( 74 CR_DEFINE_STATIC_LOCAL(
78 base::FilePath, drive_root_path, 75 base::FilePath, drive_root_path,
79 (GetDriveGrandRootPath().AppendASCII(kDriveMyDriveRootDirName))); 76 (GetDriveGrandRootPath().AppendASCII(kDriveMyDriveRootDirName)));
80 return drive_root_path; 77 return drive_root_path;
81 } 78 }
82 79
83 base::FilePath GetDriveMountPointPathForUserIdHash(
84 const std::string user_id_hash) {
85 static const base::FilePath::CharType kSpecialMountPointRoot[] =
86 FILE_PATH_LITERAL("/special");
87 static const char kDriveMountPointNameBase[] = "drive";
88 return base::FilePath(kSpecialMountPointRoot)
89 .AppendASCII(net::EscapeQueryParamValue(
90 kDriveMountPointNameBase +
91 (user_id_hash.empty() ? "" : "-" + user_id_hash),
92 false));
93 }
94
95 bool IsUnderDriveMountPoint(const base::FilePath& path) {
96 return !ExtractDrivePath(path).empty();
97 }
98
99 base::FilePath ExtractDrivePath(const base::FilePath& path) {
100 std::vector<base::FilePath::StringType> components;
101 path.GetComponents(&components);
102 if (components.size() < 3)
103 return base::FilePath();
104 if (components[0] != FILE_PATH_LITERAL("/"))
105 return base::FilePath();
106 if (components[1] != FILE_PATH_LITERAL("special"))
107 return base::FilePath();
108 static const base::FilePath::CharType kPrefix[] = FILE_PATH_LITERAL("drive");
109 if (components[2].compare(0, arraysize(kPrefix) - 1, kPrefix) != 0)
110 return base::FilePath();
111
112 base::FilePath drive_path = GetDriveGrandRootPath();
113 for (size_t i = 3; i < components.size(); ++i)
114 drive_path = drive_path.Append(components[i]);
115 return drive_path;
116 }
117
118 std::string EscapeCacheFileName(const std::string& filename) { 80 std::string EscapeCacheFileName(const std::string& filename) {
119 // This is based on net/base/escape.cc: net::(anonymous namespace)::Escape 81 // This is based on net/base/escape.cc: net::(anonymous namespace)::Escape
120 std::string escaped; 82 std::string escaped;
121 for (size_t i = 0; i < filename.size(); ++i) { 83 for (size_t i = 0; i < filename.size(); ++i) {
122 char c = filename[i]; 84 char c = filename[i];
123 if (c == '%' || c == '.' || c == '/') { 85 if (c == '%' || c == '.' || c == '/') {
124 base::StringAppendF(&escaped, "%%%02X", c); 86 base::StringAppendF(&escaped, "%%%02X", c);
125 } else { 87 } else {
126 escaped.push_back(c); 88 escaped.push_back(c);
127 } 89 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 GURL ReadUrlFromGDocFile(const base::FilePath& file_path) { 133 GURL ReadUrlFromGDocFile(const base::FilePath& file_path) {
172 return GURL(ReadStringFromGDocFile(file_path, "url")); 134 return GURL(ReadStringFromGDocFile(file_path, "url"));
173 } 135 }
174 136
175 std::string ReadResourceIdFromGDocFile(const base::FilePath& file_path) { 137 std::string ReadResourceIdFromGDocFile(const base::FilePath& file_path) {
176 return ReadStringFromGDocFile(file_path, "resource_id"); 138 return ReadStringFromGDocFile(file_path, "resource_id");
177 } 139 }
178 140
179 } // namespace util 141 } // namespace util
180 } // namespace drive 142 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698