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

Side by Side Diff: webkit/plugins/ppapi/ppb_file_ref_impl.cc

Issue 12163003: Add FilePath to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 "webkit/plugins/ppapi/ppb_file_ref_impl.h" 5 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "googleurl/src/gurl.h" 9 #include "googleurl/src/gurl.h"
10 #include "net/base/escape.h" 10 #include "net/base/escape.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 return true; 48 return true;
49 } 49 }
50 50
51 void TrimTrailingSlash(std::string* path) { 51 void TrimTrailingSlash(std::string* path) {
52 // If this path ends with a slash, then normalize it away unless path is the 52 // If this path ends with a slash, then normalize it away unless path is the
53 // root path. 53 // root path.
54 if (path->size() > 1 && path->at(path->size() - 1) == '/') 54 if (path->size() > 1 && path->at(path->size() - 1) == '/')
55 path->erase(path->size() - 1, 1); 55 path->erase(path->size() - 1, 1);
56 } 56 }
57 57
58 std::string GetNameForExternalFilePath(const FilePath& in_path) { 58 std::string GetNameForExternalFilePath(const base::FilePath& in_path) {
59 const FilePath::StringType& path = in_path.value(); 59 const base::FilePath::StringType& path = in_path.value();
60 size_t pos = path.rfind(FilePath::kSeparators[0]); 60 size_t pos = path.rfind(base::FilePath::kSeparators[0]);
61 CHECK(pos != FilePath::StringType::npos); 61 CHECK(pos != base::FilePath::StringType::npos);
62 #if defined(OS_WIN) 62 #if defined(OS_WIN)
63 return WideToUTF8(path.substr(pos + 1)); 63 return WideToUTF8(path.substr(pos + 1));
64 #elif defined(OS_POSIX) 64 #elif defined(OS_POSIX)
65 return path.substr(pos + 1); 65 return path.substr(pos + 1);
66 #else 66 #else
67 #error "Unsupported platform." 67 #error "Unsupported platform."
68 #endif 68 #endif
69 } 69 }
70 70
71 std::string GetNameForVirtualFilePath(const std::string& path) { 71 std::string GetNameForVirtualFilePath(const std::string& path) {
72 if (path.size() == 1 && path[0] == '/') 72 if (path.size() == 1 && path[0] == '/')
73 return path; 73 return path;
74 74
75 // There should always be a leading slash at least! 75 // There should always be a leading slash at least!
76 size_t pos = path.rfind('/'); 76 size_t pos = path.rfind('/');
77 CHECK(pos != std::string::npos); 77 CHECK(pos != std::string::npos);
78 return path.substr(pos + 1); 78 return path.substr(pos + 1);
79 } 79 }
80 80
81 } // namespace 81 } // namespace
82 82
83 PPB_FileRef_Impl::PPB_FileRef_Impl(const PPB_FileRef_CreateInfo& info, 83 PPB_FileRef_Impl::PPB_FileRef_Impl(const PPB_FileRef_CreateInfo& info,
84 PPB_FileSystem_Impl* file_system) 84 PPB_FileSystem_Impl* file_system)
85 : PPB_FileRef_Shared(::ppapi::OBJECT_IS_IMPL, info), 85 : PPB_FileRef_Shared(::ppapi::OBJECT_IS_IMPL, info),
86 file_system_(file_system), 86 file_system_(file_system),
87 external_file_system_path_() { 87 external_file_system_path_() {
88 } 88 }
89 89
90 PPB_FileRef_Impl::PPB_FileRef_Impl(const PPB_FileRef_CreateInfo& info, 90 PPB_FileRef_Impl::PPB_FileRef_Impl(const PPB_FileRef_CreateInfo& info,
91 const FilePath& external_file_path) 91 const base::FilePath& external_file_path)
92 : PPB_FileRef_Shared(::ppapi::OBJECT_IS_IMPL, info), 92 : PPB_FileRef_Shared(::ppapi::OBJECT_IS_IMPL, info),
93 file_system_(), 93 file_system_(),
94 external_file_system_path_(external_file_path) { 94 external_file_system_path_(external_file_path) {
95 } 95 }
96 96
97 PPB_FileRef_Impl::~PPB_FileRef_Impl() { 97 PPB_FileRef_Impl::~PPB_FileRef_Impl() {
98 } 98 }
99 99
100 // static 100 // static
101 PPB_FileRef_Impl* PPB_FileRef_Impl::CreateInternal(PP_Resource pp_file_system, 101 PPB_FileRef_Impl* PPB_FileRef_Impl::CreateInternal(PP_Resource pp_file_system,
(...skipping 23 matching lines...) Expand all
125 TrimTrailingSlash(&info.path); 125 TrimTrailingSlash(&info.path);
126 126
127 info.name = GetNameForVirtualFilePath(info.path); 127 info.name = GetNameForVirtualFilePath(info.path);
128 128
129 return new PPB_FileRef_Impl(info, file_system); 129 return new PPB_FileRef_Impl(info, file_system);
130 } 130 }
131 131
132 // static 132 // static
133 PPB_FileRef_Impl* PPB_FileRef_Impl::CreateExternal( 133 PPB_FileRef_Impl* PPB_FileRef_Impl::CreateExternal(
134 PP_Instance instance, 134 PP_Instance instance,
135 const FilePath& external_file_path, 135 const base::FilePath& external_file_path,
136 const std::string& display_name) { 136 const std::string& display_name) {
137 PPB_FileRef_CreateInfo info; 137 PPB_FileRef_CreateInfo info;
138 info.resource = HostResource::MakeInstanceOnly(instance); 138 info.resource = HostResource::MakeInstanceOnly(instance);
139 info.file_system_type = PP_FILESYSTEMTYPE_EXTERNAL; 139 info.file_system_type = PP_FILESYSTEMTYPE_EXTERNAL;
140 if (display_name.empty()) 140 if (display_name.empty())
141 info.name = GetNameForExternalFilePath(external_file_path); 141 info.name = GetNameForExternalFilePath(external_file_path);
142 else 142 else
143 info.name = display_name; 143 info.name = display_name;
144 144
145 return new PPB_FileRef_Impl(info, external_file_path); 145 return new PPB_FileRef_Impl(info, external_file_path);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 PP_Var PPB_FileRef_Impl::GetAbsolutePath() { 242 PP_Var PPB_FileRef_Impl::GetAbsolutePath() {
243 if (GetFileSystemType() != PP_FILESYSTEMTYPE_EXTERNAL) 243 if (GetFileSystemType() != PP_FILESYSTEMTYPE_EXTERNAL)
244 return GetPath(); 244 return GetPath();
245 if (!external_path_var_.get()) { 245 if (!external_path_var_.get()) {
246 external_path_var_ = new StringVar( 246 external_path_var_ = new StringVar(
247 external_file_system_path_.AsUTF8Unsafe()); 247 external_file_system_path_.AsUTF8Unsafe());
248 } 248 }
249 return external_path_var_->GetPPVar(); 249 return external_path_var_->GetPPVar();
250 } 250 }
251 251
252 FilePath PPB_FileRef_Impl::GetSystemPath() const { 252 base::FilePath PPB_FileRef_Impl::GetSystemPath() const {
253 if (GetFileSystemType() != PP_FILESYSTEMTYPE_EXTERNAL) { 253 if (GetFileSystemType() != PP_FILESYSTEMTYPE_EXTERNAL) {
254 NOTREACHED(); 254 NOTREACHED();
255 return FilePath(); 255 return base::FilePath();
256 } 256 }
257 return external_file_system_path_; 257 return external_file_system_path_;
258 } 258 }
259 259
260 GURL PPB_FileRef_Impl::GetFileSystemURL() const { 260 GURL PPB_FileRef_Impl::GetFileSystemURL() const {
261 if (GetFileSystemType() != PP_FILESYSTEMTYPE_LOCALPERSISTENT && 261 if (GetFileSystemType() != PP_FILESYSTEMTYPE_LOCALPERSISTENT &&
262 GetFileSystemType() != PP_FILESYSTEMTYPE_LOCALTEMPORARY && 262 GetFileSystemType() != PP_FILESYSTEMTYPE_LOCALTEMPORARY &&
263 GetFileSystemType() != PP_FILESYSTEMTYPE_EXTERNAL) { 263 GetFileSystemType() != PP_FILESYSTEMTYPE_EXTERNAL) {
264 NOTREACHED(); 264 NOTREACHED();
265 return GURL(); 265 return GURL();
(...skipping 14 matching lines...) Expand all
280 return file_system_ && file_system_->opened(); 280 return file_system_ && file_system_->opened();
281 } 281 }
282 282
283 bool PPB_FileRef_Impl::IsValidNonExternalFileSystem() const { 283 bool PPB_FileRef_Impl::IsValidNonExternalFileSystem() const {
284 return file_system_ && file_system_->opened() && 284 return file_system_ && file_system_->opened() &&
285 file_system_->type() != PP_FILESYSTEMTYPE_EXTERNAL; 285 file_system_->type() != PP_FILESYSTEMTYPE_EXTERNAL;
286 } 286 }
287 287
288 } // namespace ppapi 288 } // namespace ppapi
289 } // namespace webkit 289 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/ppb_file_ref_impl.h ('k') | webkit/plugins/ppapi/quota_file_io_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698