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

Side by Side Diff: chrome/browser/file_system/file_system_host_context.cc

Issue 3244002: (2nd try) Add a helper class that keeps per-profile information for FileSystem API (Closed)
Patch Set: Created 10 years, 3 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
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/file_system/file_system_host_context.h"
6
7 #include "base/file_util.h"
8 #include "base/logging.h"
9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/profile.h"
11 #include "third_party/WebKit/WebKit/chromium/public/WebFileSystem.h"
12 #include "third_party/WebKit/WebKit/chromium/public/WebCString.h"
13 #include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h"
14
15 const FilePath::CharType FileSystemHostContext::kFileSystemDirectory[] =
16 FILE_PATH_LITERAL("FileSystem");
17
18 const char FileSystemHostContext::kPersistentName[] = "Persistent";
19 const char FileSystemHostContext::kTemporaryName[] = "Temporary";
20
21 FileSystemHostContext::FileSystemHostContext(
22 const FilePath& data_path, bool is_incognito)
23 : base_path_(data_path.Append(kFileSystemDirectory)),
24 is_incognito_(is_incognito) {
25 }
26
27 bool FileSystemHostContext::GetFileSystemRootPath(
28 const GURL& origin_url, WebKit::WebFileSystem::Type type,
29 FilePath* root_path, std::string* name) const {
30 // TODO(kinuko): should return an isolated temporary file system space.
31 if (is_incognito_)
32 return false;
33 std::string storage_identifier = GetStorageIdentifierFromURL(origin_url);
34 switch (type) {
35 case WebKit::WebFileSystem::TypeTemporary:
36 if (root_path)
37 *root_path = base_path_.AppendASCII(storage_identifier)
38 .AppendASCII(kTemporaryName);
39 if (name)
40 *name = storage_identifier + ":" + kTemporaryName;
41 return true;
42 case WebKit::WebFileSystem::TypePersistent:
43 if (root_path)
44 *root_path = base_path_.AppendASCII(storage_identifier)
45 .AppendASCII(kPersistentName);
46 if (name)
47 *name = storage_identifier + ":" + kPersistentName;
48 return true;
49 }
50 LOG(WARNING) << "Unknown filesystem type is requested:" << type;
51 return false;
52 }
53
54 bool FileSystemHostContext::CheckValidFileSystemPath(
55 const FilePath& path) const {
56 // Any paths that includes parent references are considered invalid.
57 return !path.ReferencesParent() && base_path_.IsParent(path);
58 }
59
60 std::string FileSystemHostContext::GetStorageIdentifierFromURL(
61 const GURL& url) {
62 WebKit::WebSecurityOrigin web_security_origin =
63 WebKit::WebSecurityOrigin::createFromString(UTF8ToUTF16(url.spec()));
64 return web_security_origin.databaseIdentifier().utf8();
65 }
OLDNEW
« no previous file with comments | « chrome/browser/file_system/file_system_host_context.h ('k') | chrome/browser/file_system/file_system_host_context_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698