diff options
| author | pilgrim <pilgrim@chromium.org> | 2014-09-03 17:05:24 -0700 |
|---|---|---|
| committer | Commit bot <commit-bot@chromium.org> | 2014-09-04 00:34:39 +0000 |
| commit | f55d19fce5e8521d5e269739e2e0e553dcb61bf2 (patch) | |
| tree | f5bbf67615c08dcb5d7cf68e11dea3f0d04a4080 | |
| parent | 37e866f487685f176c1861ecc507a2f25e2c1a33 (diff) | |
| download | chromium_src-f55d19fce5e8521d5e269739e2e0e553dcb61bf2.zip chromium_src-f55d19fce5e8521d5e269739e2e0e553dcb61bf2.tar.gz chromium_src-f55d19fce5e8521d5e269739e2e0e553dcb61bf2.tar.bz2 | |
Move fileapi-related files from webkit/common/ to storage/common/ and set up redirect headers
BUG=338338
TBR=darin@chromium.org
Review URL: https://codereview.chromium.org/524983002
Cr-Commit-Position: refs/heads/master@{#293228}
66 files changed, 1120 insertions, 1091 deletions
diff --git a/android_webview/native/webview_native.gyp b/android_webview/native/webview_native.gyp index 60e09ad..790d40e 100644 --- a/android_webview/native/webview_native.gyp +++ b/android_webview/native/webview_native.gyp @@ -19,11 +19,11 @@ '../../media/media.gyp:player_android', '../../net/net.gyp:net', '../../skia/skia.gyp:skia', + '../../storage/storage_common.gyp:storage_common', '../../ui/base/ui_base.gyp:ui_base', '../../ui/gfx/gfx.gyp:gfx', '../../ui/gfx/gfx.gyp:gfx_geometry', '../../webkit/storage_browser.gyp:storage', - '../../webkit/storage_common.gyp:storage_common', '../../third_party/boringssl/boringssl.gyp:boringssl', 'android_webview_native_jni', ], diff --git a/build/whitespace_file.txt b/build/whitespace_file.txt index b4ab204..6155a3f 100644 --- a/build/whitespace_file.txt +++ b/build/whitespace_file.txt @@ -135,3 +135,5 @@ Suddenly Domo-Kun found itself in a room filled with dazzling mirrors. A herd of wild gits appears! Time for CQ :D And one more for sizes.py... + +Sigh. diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn index 443c700..325ed73 100644 --- a/chrome/browser/BUILD.gn +++ b/chrome/browser/BUILD.gn @@ -166,6 +166,7 @@ static_library("browser") { "//mojo/system", "//net:extras", "//net:net_with_v8", + "//storage/common", "//third_party/WebKit/public:resources", "//third_party/expat", "//third_party/leveldatabase", @@ -180,8 +181,6 @@ static_library("browser") { "//ui/web_dialogs", "//v8", "//webkit/browser:storage", - "//webkit/common", - "//webkit/common:storage_common", ## TODO(tonyg): Remove this dependency (crbug.com/280157). #"../testing/perf/perf_test.gyp:*", TODO(GYP) ] diff --git a/chrome/browser/extensions/BUILD.gn b/chrome/browser/extensions/BUILD.gn index 58f750e..8beed8a 100644 --- a/chrome/browser/extensions/BUILD.gn +++ b/chrome/browser/extensions/BUILD.gn @@ -57,6 +57,7 @@ static_library("extensions") { "//extensions/strings", "//net", "//skia", + "//storage/common", "//sync", "//third_party/WebKit/public:resources", "//third_party/cacheinvalidation", @@ -72,7 +73,6 @@ static_library("extensions") { "//ui/strings", "//url", "//webkit/browser:storage", - "//webkit/common:storage_common", ] forward_dependent_configs_from = [ diff --git a/chrome/browser/ui/BUILD.gn b/chrome/browser/ui/BUILD.gn index 02d0744..077de8c 100644 --- a/chrome/browser/ui/BUILD.gn +++ b/chrome/browser/ui/BUILD.gn @@ -108,8 +108,7 @@ static_library("ui") { "//ui/web_dialogs", "//v8", "//webkit/browser:storage", - "//webkit/common", - "//webkit/common:storage_common", + "//storage/common", ] # TODO(GYP) #'defines': [ diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index d12924b..c23766e 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -2926,6 +2926,7 @@ '../mojo/mojo_base.gyp:mojo_system_impl', '../net/net.gyp:net_extras', '../net/net.gyp:net_with_v8', + '../storage/storage_common.gyp:storage_common', # TODO(tonyg): Remove this dependency (crbug.com/280157). '../testing/perf/perf_test.gyp:*', '../third_party/expat/expat.gyp:expat', @@ -2940,7 +2941,6 @@ '../ui/web_dialogs/web_dialogs.gyp:web_dialogs', '../v8/tools/gyp/v8.gyp:v8', '../webkit/storage_browser.gyp:storage', - '../webkit/storage_common.gyp:storage_common', ], 'sources': [ '<@(chrome_browser_non_ios_sources)', diff --git a/chrome/chrome_browser_chromeos.gypi b/chrome/chrome_browser_chromeos.gypi index b7e75cf..dea5a27 100644 --- a/chrome/chrome_browser_chromeos.gypi +++ b/chrome/chrome_browser_chromeos.gypi @@ -73,6 +73,7 @@ '../net/net.gyp:net', '../ppapi/ppapi_internal.gyp:ppapi_ipc', # For PpapiMsg_LoadPlugin '../skia/skia.gyp:skia', + '../storage/storage_common.gyp:storage_common', '../sync/sync.gyp:sync', '../third_party/adobe/flash/flash_player.gyp:flapper_version_h', '../third_party/cacheinvalidation/cacheinvalidation.gyp:cacheinvalidation', @@ -106,7 +107,6 @@ '../url/url.gyp:url_lib', '../v8/tools/gyp/v8.gyp:v8', '../webkit/storage_browser.gyp:storage', - '../webkit/storage_common.gyp:storage_common', 'chrome_resources.gyp:chrome_strings', ], 'defines': [ diff --git a/chrome/chrome_browser_extensions.gypi b/chrome/chrome_browser_extensions.gypi index 5c9b97e..fd82487 100644 --- a/chrome/chrome_browser_extensions.gypi +++ b/chrome/chrome_browser_extensions.gypi @@ -965,6 +965,7 @@ '../extensions/extensions_strings.gyp:extensions_strings', '../net/net.gyp:net', '../skia/skia.gyp:skia', + '../storage/storage_common.gyp:storage_common', '../sync/sync.gyp:sync', '../third_party/cacheinvalidation/cacheinvalidation.gyp:cacheinvalidation', '../third_party/icu/icu.gyp:icui18n', @@ -980,7 +981,6 @@ '../ui/strings/ui_strings.gyp:ui_strings', '../url/url.gyp:url_lib', '../webkit/storage_browser.gyp:storage', - '../webkit/storage_common.gyp:storage_common', ], 'include_dirs': [ '..', diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi index 0d0723a..4a5d16c 100644 --- a/chrome/chrome_browser_ui.gypi +++ b/chrome/chrome_browser_ui.gypi @@ -2627,6 +2627,7 @@ '../media/media.gyp:media', '../mojo/mojo_base.gyp:mojo_system_impl', '../net/net.gyp:net_with_v8', + '../storage/storage_common.gyp:storage_common', '../third_party/expat/expat.gyp:expat', '../third_party/leveldatabase/leveldatabase.gyp:leveldatabase', '../third_party/libjingle/libjingle.gyp:libjingle', @@ -2637,7 +2638,6 @@ '../ui/web_dialogs/web_dialogs.gyp:web_dialogs', '../v8/tools/gyp/v8.gyp:v8', '../webkit/storage_browser.gyp:storage', - '../webkit/storage_common.gyp:storage_common', ], 'defines': [ '<@(nacl_defines)', diff --git a/chrome/renderer/BUILD.gn b/chrome/renderer/BUILD.gn index dbee281..8aec953 100644 --- a/chrome/renderer/BUILD.gn +++ b/chrome/renderer/BUILD.gn @@ -65,7 +65,7 @@ static_library("renderer") { "//ui/surface", "//v8:v8", "//webkit/child", - "//webkit/common", + "//storage/common", ] if (enable_nacl) { diff --git a/content/browser/BUILD.gn b/content/browser/BUILD.gn index 85798bf..26e1f05 100644 --- a/content/browser/BUILD.gn +++ b/content/browser/BUILD.gn @@ -98,6 +98,7 @@ source_set("browser") { "//mojo/public/interfaces/application", "//mojo/public/js/bindings", "//net:http_server", + "//storage/common", "//third_party/WebKit/public:resources", "//third_party/angle:commit_id", "//third_party/icu", @@ -106,8 +107,6 @@ source_set("browser") { "//ui/resources", "//ui/surface", "//webkit/browser:storage", - "//webkit/common", - "//webkit/common:storage_common", ] } diff --git a/content/child/BUILD.gn b/content/child/BUILD.gn index d9b9a5b..e078d3a 100644 --- a/content/child/BUILD.gn +++ b/content/child/BUILD.gn @@ -94,7 +94,7 @@ source_set("child") { "//third_party/WebKit/public:resources", "//third_party/npapi", "//webkit/child", - "//webkit/common", + "//storage/common", ] } diff --git a/content/common/BUILD.gn b/content/common/BUILD.gn index 40639a7..e41d84c 100644 --- a/content/common/BUILD.gn +++ b/content/common/BUILD.gn @@ -64,8 +64,7 @@ source_set("common") { "//third_party/WebKit/public:blink", "//ui/gl", "//webkit/browser:storage", - "//webkit/common", - "//webkit/common:storage_common", + "//storage/common", "//webkit/common/gpu", ] } diff --git a/content/content_browser.gypi b/content/content_browser.gypi index 7006e40..85a65e9 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -1597,12 +1597,11 @@ '../mojo/mojo_base.gyp:mojo_cpp_bindings', '../mojo/mojo_base.gyp:mojo_js_bindings', '../net/net.gyp:http_server', + '../storage/storage_common.gyp:storage_common', '../third_party/angle/src/build_angle.gyp:commit_id', '../third_party/leveldatabase/leveldatabase.gyp:leveldatabase', '../ui/surface/surface.gyp:surface', - '../webkit/common/webkit_common.gyp:webkit_common', '../webkit/storage_browser.gyp:storage', - '../webkit/storage_common.gyp:storage_common', ], }], ['enable_printing!=0', { diff --git a/content/content_child.gypi b/content/content_child.gypi index c61d6ff..5da4bc3 100644 --- a/content/content_child.gypi +++ b/content/content_child.gypi @@ -324,11 +324,11 @@ 'dependencies': [ 'app/resources/content_resources.gyp:content_resources', 'app/strings/content_strings.gyp:content_strings', + '../storage/storage_common.gyp:storage_common', '../third_party/WebKit/public/blink.gyp:blink', '../third_party/WebKit/public/blink_resources.gyp:blink_resources', '../third_party/npapi/npapi.gyp:npapi', '../webkit/child/webkit_child.gyp:webkit_child', - '../webkit/common/webkit_common.gyp:webkit_common', ], }], ['use_aura==1', { diff --git a/content/content_common.gypi b/content/content_common.gypi index 889d754..cfd4abe 100644 --- a/content/content_common.gypi +++ b/content/content_common.gypi @@ -564,12 +564,11 @@ '../mojo/mojo_base.gyp:mojo_cpp_bindings', '../mojo/mojo_base.gyp:mojo_environment_chromium', '../mojo/mojo_base.gyp:mojo_system_impl', + '../storage/storage_common.gyp:storage_common', '../third_party/WebKit/public/blink.gyp:blink', '../ui/gl/gl.gyp:gl', '../webkit/common/gpu/webkit_gpu.gyp:webkit_gpu', - '../webkit/common/webkit_common.gyp:webkit_common', '../webkit/storage_browser.gyp:storage', - '../webkit/storage_common.gyp:storage_common', ], 'actions': [ { diff --git a/content/content_renderer.gypi b/content/content_renderer.gypi index ce6e115..2b74476 100644 --- a/content/content_renderer.gypi +++ b/content/content_renderer.gypi @@ -18,6 +18,7 @@ '../mojo/mojo_base.gyp:mojo_js_bindings_lib', '../net/net.gyp:net', '../skia/skia.gyp:skia', + '../storage/storage_common.gyp:storage_common', '../third_party/WebKit/public/blink.gyp:blink', '../third_party/icu/icu.gyp:icui18n', '../third_party/icu/icu.gyp:icuuc', @@ -32,7 +33,6 @@ '../ui/surface/surface.gyp:surface', '../v8/tools/gyp/v8.gyp:v8', '../webkit/common/gpu/webkit_gpu.gyp:webkit_gpu', - '../webkit/storage_common.gyp:storage_common', ], 'include_dirs': [ '..', diff --git a/content/content_tests.gypi b/content/content_tests.gypi index 69675f4..2b928e8 100644 --- a/content/content_tests.gypi +++ b/content/content_tests.gypi @@ -198,6 +198,7 @@ 'dependencies': [ '../net/net.gyp:net_test_support', '../skia/skia.gyp:skia', + '../storage/storage_common.gyp:storage_common', '../testing/gmock.gyp:gmock', '../testing/gtest.gyp:gtest', '../ui/accessibility/accessibility.gyp:ax_gen', @@ -210,7 +211,6 @@ '../ui/gfx/gfx.gyp:gfx_test_support', '../ui/resources/ui_resources.gyp:ui_resources', '../url/url.gyp:url_lib', - '../webkit/common/webkit_common.gyp:webkit_common', 'browser/speech/proto/speech_proto.gyp:speech_proto', 'content.gyp:content_app_both', 'content.gyp:content_browser', @@ -277,13 +277,13 @@ '../ppapi/ppapi_internal.gyp:ppapi_proxy', '../ppapi/ppapi_internal.gyp:ppapi_shared', '../ppapi/ppapi_internal.gyp:ppapi_unittest_shared', + '../storage/storage_common.gyp:storage_common', '../third_party/WebKit/public/blink.gyp:blink', '../ui/compositor/compositor.gyp:compositor_test_support', '../ui/surface/surface.gyp:surface', '../v8/tools/gyp/v8.gyp:v8', '../webkit/common/gpu/webkit_gpu.gyp:webkit_gpu', '../webkit/storage_browser.gyp:storage', - '../webkit/storage_common.gyp:storage_common', ], 'export_dependent_settings': [ '../third_party/WebKit/public/blink.gyp:blink', @@ -759,6 +759,7 @@ '../ipc/ipc.gyp:test_support_ipc', '../media/media.gyp:media_test_support', '../media/media.gyp:shared_memory_support', + '../storage/storage_common.gyp:storage_common', '../third_party/WebKit/public/blink.gyp:blink', '../third_party/icu/icu.gyp:icui18n', '../third_party/icu/icu.gyp:icuuc', @@ -766,7 +767,6 @@ '../third_party/libjingle/libjingle.gyp:libjingle', '../ui/gl/gl.gyp:gl', '../webkit/storage_browser.gyp:storage', - '../webkit/storage_common.gyp:storage_common', ], }], ['enable_plugins==0', { diff --git a/content/renderer/BUILD.gn b/content/renderer/BUILD.gn index f84e57a..c74c5ba 100644 --- a/content/renderer/BUILD.gn +++ b/content/renderer/BUILD.gn @@ -35,6 +35,7 @@ source_set("renderer") { "//mojo/public/interfaces/application", "//net", "//skia", + "//storage/common", "//third_party/icu", "//third_party/libjingle", "//third_party/npapi", @@ -46,8 +47,6 @@ source_set("renderer") { "//ui/surface", "//v8", "//webkit/child", - "//webkit/common", - "//webkit/common:storage_common", "//webkit/common/gpu", ] diff --git a/content/test/BUILD.gn b/content/test/BUILD.gn index 8218f3e..ba398b7 100644 --- a/content/test/BUILD.gn +++ b/content/test/BUILD.gn @@ -32,7 +32,7 @@ static_library("test_support") { "//ui/gfx:test_support", "//ui/resources", "//url", - "//webkit/common", + "//storage/common", ] if (!is_ios) { @@ -53,13 +53,13 @@ static_library("test_support") { "//ppapi:ppapi_proxy", "//ppapi:ppapi_shared", "//ppapi:ppapi_unittest_shared", + "//storage/common", "//third_party/WebKit/public:blink", "//ui/surface", "//v8", "//webkit/child", "//webkit/common/gpu", "//webkit/browser:storage", - "//webkit/common:storage_common", ] forward_dependent_configs_from = [ diff --git a/storage/DEPS b/storage/DEPS new file mode 100644 index 0000000..8e3d4fd --- /dev/null +++ b/storage/DEPS @@ -0,0 +1,5 @@ +include_rules = [ + "+net", + "+sql", + "+third_party/WebKit/public/platform", +] diff --git a/storage/OWNERS b/storage/OWNERS new file mode 100644 index 0000000..a1327dd --- /dev/null +++ b/storage/OWNERS @@ -0,0 +1,6 @@ +darin@chromium.org +jamesr@chromium.org +kinuko@chromium.org +michaeln@chromium.org +piman@chromium.org +danakj@chromium.org diff --git a/webkit/common/BUILD.gn b/storage/common/BUILD.gn index 591f299..5212a92 100644 --- a/webkit/common/BUILD.gn +++ b/storage/common/BUILD.gn @@ -2,27 +2,12 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -# GYP version: webkit/common/webkit_common.gyp:webkit_common +# GYP version: storage/storage_common.gyp:storage_common component("common") { - output_name = "webkit_common" - + output_name = "storage_common" sources = [ "data_element.cc", "data_element.h", - "webkit_common_export.h", - ] - - defines = [ "WEBKIT_COMMON_IMPLEMENTATION" ] - - deps = [ - "//base", - "//url", - ] -} - -component("storage_common") { - output_name = "storage" - sources = [ "storage_common_export.h", "blob/blob_data.cc", "blob/blob_data.h", @@ -53,7 +38,6 @@ component("storage_common") { } deps = [ - ":common", "//base", "//base/third_party/dynamic_annotations", "//net", diff --git a/webkit/common/blob/blob_data.cc b/storage/common/blob/blob_data.cc index 4718c74..23f73e3 100644 --- a/webkit/common/blob/blob_data.cc +++ b/storage/common/blob/blob_data.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "webkit/common/blob/blob_data.h" +#include "storage/common/blob/blob_data.h" #include "base/logging.h" #include "base/strings/sys_string_conversions.h" diff --git a/storage/common/blob/blob_data.h b/storage/common/blob/blob_data.h new file mode 100644 index 0000000..2f48546 --- /dev/null +++ b/storage/common/blob/blob_data.h @@ -0,0 +1,98 @@ +// Copyright (c) 2012 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. + +#ifndef STORAGE_COMMON_BLOB_BLOB_DATA_H_ +#define STORAGE_COMMON_BLOB_BLOB_DATA_H_ + +#include <string> +#include <vector> + +#include "base/basictypes.h" +#include "base/files/file_path.h" +#include "base/memory/ref_counted.h" +#include "base/time/time.h" +#include "storage/common/blob/shareable_file_reference.h" +#include "storage/common/data_element.h" +#include "storage/common/storage_common_export.h" +#include "url/gurl.h" + +namespace storage { + +class STORAGE_COMMON_EXPORT BlobData + : public base::RefCounted<BlobData> { + public: + typedef storage::DataElement Item; + + // TODO(michaeln): remove the empty ctor when we fully transition to uuids. + BlobData(); + explicit BlobData(const std::string& uuid); + + void AppendData(const std::string& data) { + AppendData(data.c_str(), data.size()); + } + + void AppendData(const char* data, size_t length); + + void AppendFile(const base::FilePath& file_path, uint64 offset, uint64 length, + const base::Time& expected_modification_time); + void AppendBlob(const std::string& uuid, uint64 offset, uint64 length); + void AppendFileSystemFile(const GURL& url, uint64 offset, uint64 length, + const base::Time& expected_modification_time); + + void AttachShareableFileReference(ShareableFileReference* reference) { + shareable_files_.push_back(reference); + } + + const std::string& uuid() const { return uuid_; } + const std::vector<Item>& items() const { return items_; } + const std::string& content_type() const { return content_type_; } + void set_content_type(const std::string& content_type) { + content_type_ = content_type; + } + + const std::string& content_disposition() const { + return content_disposition_; + } + void set_content_disposition(const std::string& content_disposition) { + content_disposition_ = content_disposition; + } + + int64 GetMemoryUsage() const; + + private: + friend class base::RefCounted<BlobData>; + virtual ~BlobData(); + + std::string uuid_; + std::string content_type_; + std::string content_disposition_; + std::vector<Item> items_; + std::vector<scoped_refptr<ShareableFileReference> > shareable_files_; + + DISALLOW_COPY_AND_ASSIGN(BlobData); +}; + +#if defined(UNIT_TEST) +inline bool operator==(const BlobData& a, const BlobData& b) { + if (a.content_type() != b.content_type()) + return false; + if (a.content_disposition() != b.content_disposition()) + return false; + if (a.items().size() != b.items().size()) + return false; + for (size_t i = 0; i < a.items().size(); ++i) { + if (a.items()[i] != b.items()[i]) + return false; + } + return true; +} + +inline bool operator!=(const BlobData& a, const BlobData& b) { + return !(a == b); +} +#endif // defined(UNIT_TEST) + +} // namespace storage + +#endif // STORAGE_COMMON_BLOB_BLOB_DATA_H_ diff --git a/webkit/common/blob/scoped_file.cc b/storage/common/blob/scoped_file.cc index 19e68e1..9cfb1a8 100644 --- a/webkit/common/blob/scoped_file.cc +++ b/storage/common/blob/scoped_file.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "webkit/common/blob/scoped_file.h" +#include "storage/common/blob/scoped_file.h" #include "base/bind.h" #include "base/callback.h" diff --git a/storage/common/blob/scoped_file.h b/storage/common/blob/scoped_file.h new file mode 100644 index 0000000..4a51a46 --- /dev/null +++ b/storage/common/blob/scoped_file.h @@ -0,0 +1,94 @@ +// Copyright (c) 2013 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. + +#ifndef STORAGE_COMMON_BLOB_SCOPED_FILE_H_ +#define STORAGE_COMMON_BLOB_SCOPED_FILE_H_ + +#include <map> + +#include "base/callback_forward.h" +#include "base/files/file_path.h" +#include "base/memory/ref_counted.h" +#include "base/move.h" +#include "storage/common/storage_common_export.h" + +namespace base { +class TaskRunner; +} + +namespace storage { + +// A scoped reference for a FilePath that can optionally schedule the file +// to be deleted and/or to notify a consumer when it is going to be scoped out. +// This class supports move semantics, i.e. consumers can call Pass() to +// pass the ownership of ScopedFile. +// +// TODO(kinuko): Probably this can be moved under base or somewhere more +// common place. +class STORAGE_COMMON_EXPORT ScopedFile { + // To support destructive assignment from an l-value assignment. + // This provides Pass() method which creates an r-value for the current + // instance. (See base/move.h for details) + MOVE_ONLY_TYPE_FOR_CPP_03(ScopedFile, RValue) + + public: + typedef base::Callback<void(const base::FilePath&)> ScopeOutCallback; + typedef std::pair<ScopeOutCallback, scoped_refptr<base::TaskRunner> > + ScopeOutCallbackPair; + typedef std::vector<ScopeOutCallbackPair> ScopeOutCallbackList; + + enum ScopeOutPolicy { + DELETE_ON_SCOPE_OUT, + DONT_DELETE_ON_SCOPE_OUT, + }; + + ScopedFile(); + + // |file_task_runner| is used to schedule a file deletion if |policy| + // is DELETE_ON_SCOPE_OUT. + ScopedFile(const base::FilePath& path, + ScopeOutPolicy policy, + const scoped_refptr<base::TaskRunner>& file_task_runner); + + // Move constructor and operator. The data of r-value will be transfered + // in a destructive way. (See base/move.h) + ScopedFile(RValue other); + ScopedFile& operator=(RValue rhs) { + MoveFrom(*rhs.object); + return *this; + } + + ~ScopedFile(); + + // The |callback| is fired on |callback_runner| when the final reference + // of this instance is released. + // If release policy is DELETE_ON_SCOPE_OUT the + // callback task(s) is/are posted before the deletion is scheduled. + void AddScopeOutCallback(const ScopeOutCallback& callback, + base::TaskRunner* callback_runner); + + // The full file path. + const base::FilePath& path() const { return path_; } + + // Releases the file. After calling this, this instance will hold + // an empty file path and scoping out won't make any file deletion + // or callback dispatch. (If an owned pointer is attached to any of + // callbacks the pointer will be deleted.) + base::FilePath Release(); + + void Reset(); + + private: + // Performs destructive move from |other| to this. + void MoveFrom(ScopedFile& other); + + base::FilePath path_; + ScopeOutPolicy scope_out_policy_; + scoped_refptr<base::TaskRunner> file_task_runner_; + ScopeOutCallbackList scope_out_callbacks_; +}; + +} // namespace storage + +#endif // STORAGE_COMMON_BLOB_SCOPED_FILE_H_ diff --git a/webkit/common/blob/shareable_file_reference.cc b/storage/common/blob/shareable_file_reference.cc index 93d0631e..c2ec839 100644 --- a/webkit/common/blob/shareable_file_reference.cc +++ b/storage/common/blob/shareable_file_reference.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "webkit/common/blob/shareable_file_reference.h" +#include "storage/common/blob/shareable_file_reference.h" #include <map> @@ -84,7 +84,9 @@ scoped_refptr<ShareableFileReference> ShareableFileReference::GetOrCreate( return scoped_refptr<ShareableFileReference>(); typedef std::pair<ShareableFileMap::iterator, bool> InsertResult; - // Required for VS2010: http://connect.microsoft.com/VisualStudio/feedback/details/520043/error-converting-from-null-to-a-pointer-type-in-std-pair + // Required for VS2010: + // http://connect.microsoft.com/VisualStudio/feedback/ + // details/520043/error-converting-from-null-to-a-pointer-type-in-std-pair storage::ShareableFileReference* null_reference = NULL; InsertResult result = g_file_map.Get().Insert( ShareableFileMap::value_type(scoped_file.path(), null_reference)); diff --git a/storage/common/blob/shareable_file_reference.h b/storage/common/blob/shareable_file_reference.h new file mode 100644 index 0000000..bd9d050 --- /dev/null +++ b/storage/common/blob/shareable_file_reference.h @@ -0,0 +1,74 @@ +// Copyright (c) 2012 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. + +#ifndef STORAGE_COMMON_BLOB_SHAREABLE_FILE_REFERENCE_H_ +#define STORAGE_COMMON_BLOB_SHAREABLE_FILE_REFERENCE_H_ + +#include <vector> + +#include "storage/common/blob/scoped_file.h" + +namespace storage { + +// ShareableFileReference allows consumers to share FileReference for the +// same path if it already exists in its internal map. +// This class is non-thread-safe and all methods must be called on a single +// thread. +class STORAGE_COMMON_EXPORT ShareableFileReference + : public base::RefCounted<ShareableFileReference> { + public: + typedef ScopedFile::ScopeOutCallback FinalReleaseCallback; + + enum FinalReleasePolicy { + DELETE_ON_FINAL_RELEASE = ScopedFile::DELETE_ON_SCOPE_OUT, + DONT_DELETE_ON_FINAL_RELEASE = ScopedFile::DONT_DELETE_ON_SCOPE_OUT, + }; + + // Returns a ShareableFileReference for the given path, if no reference + // for this path exists returns NULL. + static scoped_refptr<ShareableFileReference> Get(const base::FilePath& path); + + // Returns a ShareableFileReference for the given path, creating a new + // reference if none yet exists. If there's a pre-existing reference for + // the path, the policy parameter of this method is ignored. + static scoped_refptr<ShareableFileReference> GetOrCreate( + const base::FilePath& path, + FinalReleasePolicy policy, + base::TaskRunner* file_task_runner); + + // Returns a ShareableFileReference for the given path of the |scoped_file|, + // creating a new reference if none yet exists. The ownership of |scoped_file| + // is passed to this reference. + // If there's a pre-existing reference for the path, the scope out policy + // and scope-out-callbacks of the given |scoped_file| is ignored. + // If the given scoped_file has an empty path (e.g. maybe already + // released) this returns NULL reference. + // + // TODO(kinuko): Make sure if this behavior is ok, we could alternatively + // merge callbacks to the existing one. + static scoped_refptr<ShareableFileReference> GetOrCreate( + ScopedFile scoped_file); + + // The full file path. + const base::FilePath& path() const { return scoped_file_.path(); } + + // The |callback| is fired when the final reference of this instance + // is released. If release policy is DELETE_ON_FINAL_RELEASE the + // callback task(s) is/are posted before the deletion is scheduled. + void AddFinalReleaseCallback(const FinalReleaseCallback& callback); + + private: + friend class base::RefCounted<ShareableFileReference>; + + ShareableFileReference(ScopedFile scoped_file); + ~ShareableFileReference(); + + ScopedFile scoped_file_; + + DISALLOW_COPY_AND_ASSIGN(ShareableFileReference); +}; + +} // namespace storage + +#endif // STORAGE_COMMON_BLOB_SHAREABLE_FILE_REFERENCE_H_ diff --git a/webkit/common/data_element.cc b/storage/common/data_element.cc index 024abe4..c6d52f4 100644 --- a/webkit/common/data_element.cc +++ b/storage/common/data_element.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "webkit/common/data_element.h" +#include "storage/common/data_element.h" namespace storage { @@ -46,4 +46,4 @@ void DataElement::SetToFileSystemUrlRange( expected_modification_time_ = expected_modification_time; } -} // webkit_common +} // namespace storage diff --git a/storage/common/data_element.h b/storage/common/data_element.h new file mode 100644 index 0000000..bdc8812 --- /dev/null +++ b/storage/common/data_element.h @@ -0,0 +1,127 @@ +// Copyright 2013 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. + +#ifndef STORAGE_COMMON_DATA_ELEMENT_H_ +#define STORAGE_COMMON_DATA_ELEMENT_H_ + +#include <string> +#include <vector> + +#include "base/basictypes.h" +#include "base/files/file_path.h" +#include "base/logging.h" +#include "base/time/time.h" +#include "storage/common/storage_common_export.h" +#include "url/gurl.h" + +namespace storage { + +// Represents a base Web data element. This could be either one of +// bytes, file or blob data. +class STORAGE_COMMON_EXPORT DataElement { + public: + enum Type { + TYPE_UNKNOWN = -1, + TYPE_BYTES, + TYPE_FILE, + TYPE_BLOB, + TYPE_FILE_FILESYSTEM, + }; + + DataElement(); + ~DataElement(); + + Type type() const { return type_; } + const char* bytes() const { return bytes_ ? bytes_ : &buf_[0]; } + const base::FilePath& path() const { return path_; } + const GURL& filesystem_url() const { return filesystem_url_; } + const std::string& blob_uuid() const { return blob_uuid_; } + uint64 offset() const { return offset_; } + uint64 length() const { return length_; } + const base::Time& expected_modification_time() const { + return expected_modification_time_; + } + + // Sets TYPE_BYTES data. This copies the given data into the element. + void SetToBytes(const char* bytes, int bytes_len) { + type_ = TYPE_BYTES; + buf_.assign(bytes, bytes + bytes_len); + length_ = buf_.size(); + } + + // Sets TYPE_BYTES data. This does NOT copy the given data and the caller + // should make sure the data is alive when this element is accessed. + void SetToSharedBytes(const char* bytes, int bytes_len) { + type_ = TYPE_BYTES; + bytes_ = bytes; + length_ = bytes_len; + } + + // Sets TYPE_FILE data. + void SetToFilePath(const base::FilePath& path) { + SetToFilePathRange(path, 0, kuint64max, base::Time()); + } + + // Sets TYPE_BLOB data. + void SetToBlob(const std::string& uuid) { + SetToBlobRange(uuid, 0, kuint64max); + } + + // Sets TYPE_FILE data with range. + void SetToFilePathRange(const base::FilePath& path, + uint64 offset, uint64 length, + const base::Time& expected_modification_time); + + // Sets TYPE_BLOB data with range. + void SetToBlobRange(const std::string& blob_uuid, + uint64 offset, uint64 length); + + // Sets TYPE_FILE_FILESYSTEM with range. + void SetToFileSystemUrlRange(const GURL& filesystem_url, + uint64 offset, uint64 length, + const base::Time& expected_modification_time); + + private: + Type type_; + std::vector<char> buf_; // For TYPE_BYTES. + const char* bytes_; // For TYPE_BYTES. + base::FilePath path_; // For TYPE_FILE. + GURL filesystem_url_; // For TYPE_FILE_FILESYSTEM. + std::string blob_uuid_; + uint64 offset_; + uint64 length_; + base::Time expected_modification_time_; +}; + +#if defined(UNIT_TEST) +inline bool operator==(const DataElement& a, const DataElement& b) { + if (a.type() != b.type() || + a.offset() != b.offset() || + a.length() != b.length()) + return false; + switch (a.type()) { + case DataElement::TYPE_BYTES: + return memcmp(a.bytes(), b.bytes(), b.length()) == 0; + case DataElement::TYPE_FILE: + return a.path() == b.path() && + a.expected_modification_time() == b.expected_modification_time(); + case DataElement::TYPE_BLOB: + return a.blob_uuid() == b.blob_uuid(); + case DataElement::TYPE_FILE_FILESYSTEM: + return a.filesystem_url() == b.filesystem_url(); + case DataElement::TYPE_UNKNOWN: + NOTREACHED(); + return false; + } + return false; +} + +inline bool operator!=(const DataElement& a, const DataElement& b) { + return !(a == b); +} +#endif // defined(UNIT_TEST) + +} // namespace storage + +#endif // STORAGE_COMMON_DATA_ELEMENT_H_ diff --git a/webkit/common/database/database_connections.cc b/storage/common/database/database_connections.cc index bb2eaee..adfcde1 100644 --- a/webkit/common/database/database_connections.cc +++ b/storage/common/database/database_connections.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "webkit/common/database/database_connections.h" +#include "storage/common/database/database_connections.h" #include "base/auto_reset.h" #include "base/bind.h" diff --git a/storage/common/database/database_connections.h b/storage/common/database/database_connections.h new file mode 100644 index 0000000..ab4812e --- /dev/null +++ b/storage/common/database/database_connections.h @@ -0,0 +1,99 @@ +// Copyright (c) 2011 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. + +#ifndef STORAGE_COMMON_DATABASE_DATABASE_CONNECTIONS_H_ +#define STORAGE_COMMON_DATABASE_DATABASE_CONNECTIONS_H_ + +#include <map> +#include <string> +#include <vector> + +#include "base/memory/ref_counted.h" +#include "base/strings/string16.h" +#include "base/synchronization/lock.h" +#include "storage/common/storage_common_export.h" + +namespace base { +class MessageLoopProxy; +} + +namespace storage { + +class STORAGE_COMMON_EXPORT DatabaseConnections { + public: + DatabaseConnections(); + ~DatabaseConnections(); + + bool IsEmpty() const; + bool IsDatabaseOpened(const std::string& origin_identifier, + const base::string16& database_name) const; + bool IsOriginUsed(const std::string& origin_identifier) const; + + // Returns true if this is the first connection. + bool AddConnection(const std::string& origin_identifier, + const base::string16& database_name); + + // Returns true if the last connection was removed. + bool RemoveConnection(const std::string& origin_identifier, + const base::string16& database_name); + + void RemoveAllConnections(); + void RemoveConnections( + const DatabaseConnections& connections, + std::vector<std::pair<std::string, base::string16> >* closed_dbs); + + // Database sizes can be kept only if IsDatabaseOpened returns true. + int64 GetOpenDatabaseSize(const std::string& origin_identifier, + const base::string16& database_name) const; + void SetOpenDatabaseSize(const std::string& origin_identifier, + const base::string16& database_name, + int64 size); + + // Returns a list of the connections, <origin_id, name>. + void ListConnections( + std::vector<std::pair<std::string, base::string16> > *list) const; + + private: + // Mapping from name to <openCount, size> + typedef std::map<base::string16, std::pair<int, int64> > DBConnections; + typedef std::map<std::string, DBConnections> OriginConnections; + mutable OriginConnections connections_; // mutable for GetOpenDatabaseSize + + // Returns true if the last connection was removed. + bool RemoveConnectionsHelper(const std::string& origin_identifier, + const base::string16& database_name, + int num_connections); +}; + +// A wrapper class that provides thread-safety and the +// ability to wait until all connections have closed. +// Intended for use in renderer processes. +class STORAGE_COMMON_EXPORT DatabaseConnectionsWrapper + : public base::RefCountedThreadSafe<DatabaseConnectionsWrapper> { + public: + DatabaseConnectionsWrapper(); + + // The Wait and Has methods should only be called on the + // main thread (the thread on which the wrapper is constructed). + void WaitForAllDatabasesToClose(); + bool HasOpenConnections(); + + // Add and Remove may be called on any thread. + void AddOpenConnection(const std::string& origin_identifier, + const base::string16& database_name); + void RemoveOpenConnection(const std::string& origin_identifier, + const base::string16& database_name); + private: + ~DatabaseConnectionsWrapper(); + friend class base::RefCountedThreadSafe<DatabaseConnectionsWrapper>; + + bool waiting_for_dbs_to_close_; + base::Lock open_connections_lock_; + DatabaseConnections open_connections_; + scoped_refptr<base::MessageLoopProxy> main_thread_; +}; + +} // namespace storage + +#endif // STORAGE_COMMON_DATABASE_DATABASE_CONNECTIONS_H_ diff --git a/webkit/common/database/database_identifier.cc b/storage/common/database/database_identifier.cc index b793ff7..e642a1a 100644 --- a/webkit/common/database/database_identifier.cc +++ b/storage/common/database/database_identifier.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "webkit/common/database/database_identifier.h" +#include "storage/common/database/database_identifier.h" #include "base/strings/string_number_conversions.h" #include "base/strings/string_util.h" diff --git a/storage/common/database/database_identifier.h b/storage/common/database/database_identifier.h new file mode 100644 index 0000000..a658ade --- /dev/null +++ b/storage/common/database/database_identifier.h @@ -0,0 +1,54 @@ +// Copyright 2013 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. + +#ifndef STORAGE_COMMON_DATABASE_DATABASE_IDENTIFIER_H_ +#define STORAGE_COMMON_DATABASE_DATABASE_IDENTIFIER_H_ + +#include <string> + +#include "base/basictypes.h" +#include "base/strings/string_piece.h" +#include "storage/common/storage_common_export.h" +#include "url/gurl.h" + +namespace storage { + +STORAGE_COMMON_EXPORT std::string GetIdentifierFromOrigin( + const GURL& origin); +STORAGE_COMMON_EXPORT GURL GetOriginFromIdentifier( + const std::string& identifier); + +class STORAGE_COMMON_EXPORT DatabaseIdentifier { + public: + static const DatabaseIdentifier UniqueFileIdentifier(); + static DatabaseIdentifier CreateFromOrigin(const GURL& origin); + static DatabaseIdentifier Parse(const std::string& identifier); + ~DatabaseIdentifier(); + + std::string ToString() const; + GURL ToOrigin() const; + + std::string scheme() const { return scheme_; } + std::string hostname() const { return hostname_; } + int port() const { return port_; } + bool is_unique() const { return is_unique_; } + + private: + DatabaseIdentifier(); + DatabaseIdentifier(const std::string& scheme, + const std::string& hostname, + int port, + bool is_unique, + bool is_file); + + std::string scheme_; + std::string hostname_; + int port_; + bool is_unique_; + bool is_file_; +}; + +} // namespace storage + +#endif // STORAGE_COMMON_DATABASE_DATABASE_IDENTIFIER_H_ diff --git a/webkit/common/fileapi/OWNERS b/storage/common/fileapi/OWNERS index 232db84..232db84 100644 --- a/webkit/common/fileapi/OWNERS +++ b/storage/common/fileapi/OWNERS diff --git a/webkit/common/fileapi/directory_entry.cc b/storage/common/fileapi/directory_entry.cc index ea062b4..477ede8 100644 --- a/webkit/common/fileapi/directory_entry.cc +++ b/storage/common/fileapi/directory_entry.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "webkit/common/fileapi/directory_entry.h" +#include "storage/common/fileapi/directory_entry.h" namespace storage { diff --git a/storage/common/fileapi/directory_entry.h b/storage/common/fileapi/directory_entry.h new file mode 100644 index 0000000..1b06828 --- /dev/null +++ b/storage/common/fileapi/directory_entry.h @@ -0,0 +1,38 @@ +// Copyright 2013 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. + +#ifndef STORAGE_COMMON_FILEAPI_DIRECTORY_ENTRY_H_ +#define STORAGE_COMMON_FILEAPI_DIRECTORY_ENTRY_H_ + +#include <string> + +#include "base/basictypes.h" +#include "base/files/file_path.h" +#include "base/time/time.h" +#include "storage/common/storage_common_export.h" + +namespace storage { + +// Holds metadata for file or directory entry. +struct STORAGE_COMMON_EXPORT DirectoryEntry { + enum DirectoryEntryType { + FILE, + DIRECTORY, + }; + + DirectoryEntry(); + DirectoryEntry(const std::string& name, + DirectoryEntryType type, + int64 size, + const base::Time& last_modified_time); + + base::FilePath::StringType name; + bool is_directory; + int64 size; + base::Time last_modified_time; +}; + +} // namespace storage + +#endif // STORAGE_COMMON_FILEAPI_DIRECTORY_ENTRY_H_ diff --git a/webkit/common/fileapi/file_system_info.cc b/storage/common/fileapi/file_system_info.cc index 40b868d..1a6a9cc 100644 --- a/webkit/common/fileapi/file_system_info.cc +++ b/storage/common/fileapi/file_system_info.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "webkit/common/fileapi/file_system_info.h" +#include "storage/common/fileapi/file_system_info.h" namespace storage { diff --git a/storage/common/fileapi/file_system_info.h b/storage/common/fileapi/file_system_info.h new file mode 100644 index 0000000..bb2fea9 --- /dev/null +++ b/storage/common/fileapi/file_system_info.h @@ -0,0 +1,33 @@ +// Copyright 2013 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. + +#ifndef STORAGE_COMMON_FILEAPI_FILE_SYSTEM_INFO_H_ +#define STORAGE_COMMON_FILEAPI_FILE_SYSTEM_INFO_H_ + +#include <string> + +#include "storage/common/fileapi/file_system_types.h" +#include "storage/common/storage_common_export.h" +#include "url/gurl.h" + +namespace storage { + +// This struct is used to send the necessary information for Blink to create a +// DOMFileSystem. Since Blink side only uses mount_type (rather than +// detailed/cracked filesystem type) this only contains mount_type but not type. +struct STORAGE_COMMON_EXPORT FileSystemInfo { + FileSystemInfo(); + FileSystemInfo(const std::string& filesystem_name, + const GURL& root_url, + storage::FileSystemType mount_type); + ~FileSystemInfo(); + + std::string name; + GURL root_url; + storage::FileSystemType mount_type; +}; + +} // namespace storage + +#endif // STORAGE_COMMON_FILEAPI_FILE_SYSTEM_INFO_H_ diff --git a/storage/common/fileapi/file_system_mount_option.h b/storage/common/fileapi/file_system_mount_option.h new file mode 100644 index 0000000..dc5cdc4 --- /dev/null +++ b/storage/common/fileapi/file_system_mount_option.h @@ -0,0 +1,37 @@ +// Copyright 2013 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. + +#ifndef STORAGE_COMMON_FILEAPI_FILE_SYSTEM_MOUNT_OPTION_H_ +#define STORAGE_COMMON_FILEAPI_FILE_SYSTEM_MOUNT_OPTION_H_ + +namespace storage { + +// Option for specifying if disk sync operation is wanted after copying. +enum CopySyncOption { + COPY_SYNC_OPTION_NO_SYNC, + COPY_SYNC_OPTION_SYNC, +}; + +// Conveys options for a mounted file systems. +class FileSystemMountOption { + public: + // Constructs with the default options. + FileSystemMountOption() + : copy_sync_option_(COPY_SYNC_OPTION_NO_SYNC) {} + + // Constructs with the specified component. + explicit FileSystemMountOption(CopySyncOption copy_sync_option) + : copy_sync_option_(copy_sync_option) {} + + CopySyncOption copy_sync_option() const { + return copy_sync_option_; + } + + private: + CopySyncOption copy_sync_option_; +}; + +} // namespace storage + +#endif // STORAGE_COMMON_FILEAPI_FILE_SYSTEM_MOUNT_OPTION_H_ diff --git a/storage/common/fileapi/file_system_types.h b/storage/common/fileapi/file_system_types.h new file mode 100644 index 0000000..645b759 --- /dev/null +++ b/storage/common/fileapi/file_system_types.h @@ -0,0 +1,137 @@ +// Copyright (c) 2012 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. + +#ifndef STORAGE_COMMON_FILEAPI_FILE_SYSTEM_TYPES_H_ +#define STORAGE_COMMON_FILEAPI_FILE_SYSTEM_TYPES_H_ + +#include "third_party/WebKit/public/platform/WebFileSystemType.h" + +namespace storage { + +enum FileSystemType { + // Indicates uninitialized or invalid filesystem type. + kFileSystemTypeUnknown = -1, + + // ------------------------------------------------------------------------ + // Public FileSystem types, that are embedded in filesystem: URL and exposed + // to WebKit/renderer. Both Chrome and WebKit know how to handle these types. + + // Following two types are for TEMPORARY or PERSISTENT filesystems that + // can be used by webapps via standard app-facing API + // as defined in File API: Directories and System. + // http://www.w3.org/TR/file-system-api/#temporary-vs.-persistent-storage + // They are sandboxed filesystems; all the files in the filesystems are + // placed under the profile directory with path obfuscation and quota + // enforcement. + kFileSystemTypeTemporary = blink::WebFileSystemTypeTemporary, + kFileSystemTypePersistent = blink::WebFileSystemTypePersistent, + + // Indicates non-sandboxed isolated filesystem. + kFileSystemTypeIsolated = blink::WebFileSystemTypeIsolated, + + // Indicates filesystems that are mounted externally via + // ExternalMountPoints with a well-known mount name. The mounted + // filesystems can be sandboxed or non-sandboxed. (E.g. Chrome OS mounts + // non-sandboxed removable media folder with a name 'removable', while + // chrome.syncFileSystem mounts a sandboxed filesystem with a name + // 'syncfs'.) + kFileSystemTypeExternal = blink::WebFileSystemTypeExternal, + + // ------------------------------------------------------------------------ + // Marks the beginning of internal type enum. (This is not the actual fs type) + kFileSystemInternalTypeEnumStart = 99, + + // Private FileSystem types, that should not appear in filesystem: URL as + // WebKit has no idea how to handle those types. + // + // One can register (mount) a new file system with a private file system type + // using IsolatedContext. Files in such file systems can be accessed via + // either Isolated or External public file system types (depending on + // how the file system is registered). + // See the comments for IsolatedContext and/or FileSystemURL for more details. + + // Should be used only for testing. + kFileSystemTypeTest, + + // Indicates a local filesystem where we can access files using native + // local path. + kFileSystemTypeNativeLocal, + + // Indicates a local filesystem where we can access files using native + // local path, but with restricted access. + // Restricted native local file system is in read-only mode. + kFileSystemTypeRestrictedNativeLocal, + + // Indicates a transient, isolated file system for dragged files (which could + // contain multiple dragged paths in the virtual root). + kFileSystemTypeDragged, + + // Indicates media filesystem which we can access with same manner to + // regular filesystem. + kFileSystemTypeNativeMedia, + + // Indicates media filesystem to which we need special protocol to access, + // such as MTP or PTP. + kFileSystemTypeDeviceMedia, + + // Indicates a Picasa virtual filesystem provided by Media Galleries API. + kFileSystemTypePicasa, + + // Indicates a synthetic iTunes filesystem. + kFileSystemTypeItunes, + + // Indicates a synthetic iPhoto filesystem. + kFileSystemTypeIphoto, + + // Indicates a Drive filesystem which provides access to Google Drive. + kFileSystemTypeDrive, + + // Indicates a Syncable sandboxed filesystem which can be backed by a + // cloud storage service. + kFileSystemTypeSyncable, + + // Indicates a special filesystem type for internal file sync operation + // for Syncable sandboxed filesystems. The file system is overlayed, i.e. + // points to the same sandboxed filesystem as that of kFileSystemTypeSyncable, + // but the changes made with this filesystem type are not recorded for + // further sync. + kFileSystemTypeSyncableForInternalSync, + + // Indicates an external filesystem accessible by file paths from platform + // Apps. As of writing, on non Chrome OS platform, this is merely a + // kFileSystemTypeNativeLocal. On Chrome OS, the path is parsed by + // the handlers of kFileSystemTypeExternal. + kFileSystemTypeNativeForPlatformApp, + + // Indicates an isolated filesystem which is supposed to contain one + // temporary which is supposed to go away when the last reference of + // its snapshot is dropped. + // This type is useful for creating a blob reference for a temporary + // file which must go away when the blob's last reference is dropped. + kFileSystemTypeForTransientFile, + + // Sandboxed private filesystem. This filesystem cannot be opened + // via regular OpenFileSystem, and provides private filesystem space for + // given identifier in each origin. + kFileSystemTypePluginPrivate, + + // A filesystem that is mounted via the Privet storage protocol. + kFileSystemTypeCloudDevice, + + // A filesystem that is mounted via the FileSystemProvider API. + kFileSystemTypeProvided, + + // A media filesystem such as MTP or PTP, mounted as a file storage not + // limited to media files. + kFileSystemTypeDeviceMediaAsFileStorage, + + // -------------------------------------------------------------------- + // Marks the end of internal type enum. (This is not the actual fs type) + // New internal filesystem types must be added above this line. + kFileSystemInternalTypeEnumEnd, +}; + +} // namespace storage + +#endif // STORAGE_COMMON_FILEAPI_FILE_SYSTEM_TYPES_H_ diff --git a/webkit/common/fileapi/file_system_util.cc b/storage/common/fileapi/file_system_util.cc index f5e3531..0e81843 100644 --- a/webkit/common/fileapi/file_system_util.cc +++ b/storage/common/fileapi/file_system_util.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "webkit/common/fileapi/file_system_util.h" +#include "storage/common/fileapi/file_system_util.h" #include <algorithm> @@ -13,8 +13,8 @@ #include "base/strings/utf_string_conversions.h" #include "net/base/escape.h" #include "net/base/net_errors.h" +#include "storage/common/database/database_identifier.h" #include "url/gurl.h" -#include "webkit/common/database/database_identifier.h" namespace storage { diff --git a/storage/common/fileapi/file_system_util.h b/storage/common/fileapi/file_system_util.h new file mode 100644 index 0000000..55684b6 --- /dev/null +++ b/storage/common/fileapi/file_system_util.h @@ -0,0 +1,182 @@ +// Copyright (c) 2012 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. + +#ifndef STORAGE_COMMON_FILEAPI_FILE_SYSTEM_UTIL_H_ +#define STORAGE_COMMON_FILEAPI_FILE_SYSTEM_UTIL_H_ + +#include <string> +#include <vector> + +#include "base/files/file.h" +#include "base/files/file_path.h" +#include "storage/common/fileapi/file_system_info.h" +#include "storage/common/fileapi/file_system_types.h" +#include "storage/common/quota/quota_types.h" +#include "storage/common/storage_common_export.h" +#include "third_party/WebKit/public/platform/WebFileError.h" +#include "third_party/WebKit/public/platform/WebFileSystemType.h" + +class GURL; + +namespace storage { + +STORAGE_COMMON_EXPORT extern const char kPersistentDir[]; +STORAGE_COMMON_EXPORT extern const char kTemporaryDir[]; +STORAGE_COMMON_EXPORT extern const char kExternalDir[]; +STORAGE_COMMON_EXPORT extern const char kIsolatedDir[]; +STORAGE_COMMON_EXPORT extern const char kTestDir[]; + +class STORAGE_COMMON_EXPORT VirtualPath { + public: + static const base::FilePath::CharType kRoot[]; + static const base::FilePath::CharType kSeparator; + + // Use this instead of base::FilePath::BaseName when operating on virtual + // paths. FilePath::BaseName will get confused by ':' on Windows when it + // looks like a drive letter separator; this will treat it as just another + // character. + static base::FilePath BaseName(const base::FilePath& virtual_path); + + // Use this instead of base::FilePath::DirName when operating on virtual + // paths. + static base::FilePath DirName(const base::FilePath& virtual_path); + + // Likewise, use this instead of base::FilePath::GetComponents when + // operating on virtual paths. + // Note that this assumes very clean input, with no leading slash, and + // it will not evaluate '..' components. + static void GetComponents( + const base::FilePath& path, + std::vector<base::FilePath::StringType>* components); + + static void GetComponentsUTF8Unsafe( + const base::FilePath& path, std::vector<std::string>* components); + + // Returns a path name ensuring that it begins with kRoot and all path + // separators are forward slashes /. + static base::FilePath::StringType GetNormalizedFilePath( + const base::FilePath& path); + + // Returns true if the given path begins with kRoot. + static bool IsAbsolute(const base::FilePath::StringType& path); + + // Returns true if the given path points to the root. + static bool IsRootPath(const base::FilePath& path); +}; + +// Parses filesystem scheme |url| into uncracked file system URL components. +// Example: For a URL 'filesystem:http://foo.com/temporary/foo/bar', +// |origin_url| is set to 'http://foo.com', |type| is set to +// kFileSystemTypeTemporary, and |virtual_path| is set to 'foo/bar'. +STORAGE_COMMON_EXPORT bool ParseFileSystemSchemeURL( + const GURL& url, + GURL* origin_url, + FileSystemType* type, + base::FilePath* virtual_path); + +// Returns the root URI of the filesystem that can be specified by a pair of +// |origin_url| and |type|. The returned URI can be used as a root path +// of the filesystem (e.g. <returned_URI> + "/relative/path" will compose +// a path pointing to the entry "/relative/path" in the filesystem). +// +// For Isolated filesystem this returns the 'common' root part, e.g. +// returns URL without the filesystem ID. +// +// |type| needs to be public type as the returned URI is given to the renderer. +STORAGE_COMMON_EXPORT GURL GetFileSystemRootURI(const GURL& origin_url, + FileSystemType type); + +// Returns the name for the filesystem that is specified by a pair of +// |origin_url| and |type|. +// (The name itself is neither really significant nor a formal identifier +// but can be read as the .name field of the returned FileSystem object +// as a user-friendly name in the javascript layer). +// +// |type| needs to be public type as the returned name is given to the renderer. +// +// Example: +// The name for a TEMPORARY filesystem of "http://www.example.com:80/" +// should look like: "http_www.example.host_80:temporary" +STORAGE_COMMON_EXPORT std::string +GetFileSystemName(const GURL& origin_url, FileSystemType type); + +// Converts FileSystemType |type| to/from the StorageType |storage_type| that +// is used for the unified quota system. +// (Basically this naively maps TEMPORARY storage type to TEMPORARY filesystem +// type, PERSISTENT storage type to PERSISTENT filesystem type and vice versa.) +STORAGE_COMMON_EXPORT FileSystemType + QuotaStorageTypeToFileSystemType(storage::StorageType storage_type); + +STORAGE_COMMON_EXPORT storage::StorageType + FileSystemTypeToQuotaStorageType(FileSystemType type); + +// Returns the string representation of the given filesystem |type|. +// Returns an empty string if the |type| is invalid. +STORAGE_COMMON_EXPORT std::string +GetFileSystemTypeString(FileSystemType type); + +// Sets type to FileSystemType enum that corresponds to the string name. +// Returns false if the |type_string| is invalid. +STORAGE_COMMON_EXPORT bool GetFileSystemPublicType( + std::string type_string, + blink::WebFileSystemType* type); + +// Encodes |file_path| to a string. +// Following conditions should be held: +// - StringToFilePath(FilePathToString(path)) == path +// - StringToFilePath(FilePathToString(path) + "/" + "SubDirectory") == +// path.AppendASCII("SubDirectory"); +// +// TODO(tzik): Replace CreateFilePath and FilePathToString in +// third_party/leveldatabase/env_chromium.cc with them. +STORAGE_COMMON_EXPORT std::string FilePathToString( + const base::FilePath& file_path); + +// Decode a file path from |file_path_string|. +STORAGE_COMMON_EXPORT base::FilePath StringToFilePath( + const std::string& file_path_string); + +// File error conversion +STORAGE_COMMON_EXPORT blink::WebFileError +FileErrorToWebFileError(base::File::Error error_code); + +// Generate a file system name for the given arguments. Should only be used by +// platform apps. +STORAGE_COMMON_EXPORT std::string GetIsolatedFileSystemName( + const GURL& origin_url, + const std::string& filesystem_id); + +// Find the file system id from |filesystem_name|. Should only be used by +// platform apps. This function will return false if the file system name is +// not of the form {origin}:Isolated_{id}, and will also check that there is an +// origin and id present. It will not check that the origin or id are valid. +STORAGE_COMMON_EXPORT bool CrackIsolatedFileSystemName( + const std::string& filesystem_name, + std::string* filesystem_id); + +// Validates the given isolated file system id. +STORAGE_COMMON_EXPORT bool ValidateIsolatedFileSystemId( + const std::string& filesystem_id); + +// Returns the root URI for an isolated filesystem for origin |origin_url| +// and |filesystem_id|. If the |optional_root_name| is given the resulting +// root URI will point to the subfolder within the isolated filesystem. +STORAGE_COMMON_EXPORT std::string GetIsolatedFileSystemRootURIString( + const GURL& origin_url, + const std::string& filesystem_id, + const std::string& optional_root_name); + +// Returns the root URI for an external filesystem for origin |origin_url| +// and |mount_name|. +STORAGE_COMMON_EXPORT std::string GetExternalFileSystemRootURIString( + const GURL& origin_url, + const std::string& mount_name); + +// Translates the net::Error to base::File::Error. +STORAGE_COMMON_EXPORT base::File::Error +NetErrorToFileError(int error); + +} // namespace storage + +#endif // STORAGE_COMMON_FILEAPI_FILE_SYSTEM_UTIL_H_ diff --git a/webkit/common/quota/quota_status_code.cc b/storage/common/quota/quota_status_code.cc index 1139589..b3976e5 100644 --- a/webkit/common/quota/quota_status_code.cc +++ b/storage/common/quota/quota_status_code.cc @@ -3,7 +3,7 @@ // found in the LICENSE file. #include "base/logging.h" -#include "webkit/common/quota/quota_status_code.h" +#include "storage/common/quota/quota_status_code.h" namespace storage { diff --git a/storage/common/quota/quota_status_code.h b/storage/common/quota/quota_status_code.h new file mode 100644 index 0000000..00da235 --- /dev/null +++ b/storage/common/quota/quota_status_code.h @@ -0,0 +1,28 @@ +// Copyright 2013 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. + +#ifndef STORAGE_COMMON_QUOTA_QUOTA_STATUS_CODE_H_ +#define STORAGE_COMMON_QUOTA_QUOTA_STATUS_CODE_H_ + +#include "storage/common/storage_common_export.h" +#include "third_party/WebKit/public/platform/WebStorageQuotaError.h" + +namespace storage { + +enum QuotaStatusCode { + kQuotaStatusOk = 0, + kQuotaErrorNotSupported = blink::WebStorageQuotaErrorNotSupported, + kQuotaErrorInvalidModification = + blink::WebStorageQuotaErrorInvalidModification, + kQuotaErrorInvalidAccess = blink::WebStorageQuotaErrorInvalidAccess, + kQuotaErrorAbort = blink::WebStorageQuotaErrorAbort, + kQuotaStatusUnknown = -1, +}; + +STORAGE_COMMON_EXPORT const char* QuotaStatusCodeToString( + QuotaStatusCode status); + +} // namespace storage + +#endif // STORAGE_COMMON_QUOTA_QUOTA_STATUS_CODE_H_ diff --git a/storage/common/quota/quota_types.h b/storage/common/quota/quota_types.h new file mode 100644 index 0000000..c8087e6 --- /dev/null +++ b/storage/common/quota/quota_types.h @@ -0,0 +1,29 @@ +// Copyright 2013 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. + +#ifndef STORAGE_COMMON_QUOTA_QUOTA_TYPES_H_ +#define STORAGE_COMMON_QUOTA_QUOTA_TYPES_H_ + +#include "storage/common/quota/quota_status_code.h" + +namespace storage { + +enum StorageType { + kStorageTypeTemporary, + kStorageTypePersistent, + kStorageTypeSyncable, + kStorageTypeQuotaNotManaged, + kStorageTypeUnknown, + kStorageTypeLast = kStorageTypeUnknown +}; + +enum QuotaLimitType { + kQuotaLimitTypeUnknown, + kQuotaLimitTypeLimited, + kQuotaLimitTypeUnlimited, +}; + +} // namespace storage + +#endif // STORAGE_COMMON_QUOTA_QUOTA_TYPES_H_ diff --git a/webkit/common/storage_common_export.h b/storage/common/storage_common_export.h index 5f2baf4..3c97109 100644 --- a/webkit/common/storage_common_export.h +++ b/storage/common/storage_common_export.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef WEBKIT_COMMON_STORAGE_COMMON_EXPORT_H_ -#define WEBKIT_COMMON_STORAGE_COMMON_EXPORT_H_ +#ifndef STORAGE_COMMON_STORAGE_COMMON_EXPORT_H_ +#define STORAGE_COMMON_STORAGE_COMMON_EXPORT_H_ #if defined(COMPONENT_BUILD) #if defined(WIN32) @@ -26,4 +26,4 @@ #define STORAGE_COMMON_EXPORT #endif -#endif // WEBKIT_COMMON_STORAGE_COMMON_EXPORT_H_ +#endif // STORAGE_COMMON_STORAGE_COMMON_EXPORT_H_ diff --git a/webkit/storage_common.gyp b/storage/storage_common.gyp index cc95ef0..87d34b9 100644 --- a/webkit/storage_common.gyp +++ b/storage/storage_common.gyp @@ -8,7 +8,7 @@ }, 'targets': [ { - # GN version: //webkit/common:storage_common + # GN version: //storage/common 'target_name': 'storage_common', 'type': '<(component)', 'variables': { 'enable_wexit_time_destructors': 1, }, @@ -17,10 +17,11 @@ '<(DEPTH)/base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations', '<(DEPTH)/net/net.gyp:net', '<(DEPTH)/url/url.gyp:url_lib', - '<(DEPTH)/webkit/common/webkit_common.gyp:webkit_common', ], 'defines': ['STORAGE_COMMON_IMPLEMENTATION'], 'sources': [ + 'common/data_element.cc', + 'common/data_element.h', 'common/blob/blob_data.cc', 'common/blob/blob_data.h', 'common/blob/scoped_file.cc', diff --git a/webkit/DEPS b/webkit/DEPS index 6e69dfd..2d45bbb 100644 --- a/webkit/DEPS +++ b/webkit/DEPS @@ -24,6 +24,7 @@ include_rules = [ # For databases/ "+sql", + "+storage", # For gpu/ "+ui/gfx", diff --git a/webkit/browser/BUILD.gn b/webkit/browser/BUILD.gn index ab47b35..0a74f5e 100644 --- a/webkit/browser/BUILD.gn +++ b/webkit/browser/BUILD.gn @@ -2,6 +2,7 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. +# GYP version: webkit/storage_browser.gyp:storage component("storage") { output_name = "storage" sources = [ @@ -164,11 +165,10 @@ component("storage") { "//base/third_party/dynamic_annotations", "//net", "//sql", + "//storage/common", "//third_party/leveldatabase", "//third_party/sqlite", "//url", - "//webkit/common", - "//webkit/common:storage_common", ] # TODO(GYP) support chrome_multiple_dll @@ -187,6 +187,6 @@ executable("dump_file_system") { deps = [ ":storage", "//base", - "//webkit/common:storage_common", + "//storage/common", ] } diff --git a/webkit/common/blob/blob_data.h b/webkit/common/blob/blob_data.h index 6918679..25d1fa2 100644 --- a/webkit/common/blob/blob_data.h +++ b/webkit/common/blob/blob_data.h @@ -1,98 +1,5 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2014 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. -#ifndef WEBKIT_COMMON_BLOB_BLOB_DATA_H_ -#define WEBKIT_COMMON_BLOB_BLOB_DATA_H_ - -#include <string> -#include <vector> - -#include "base/basictypes.h" -#include "base/files/file_path.h" -#include "base/memory/ref_counted.h" -#include "base/time/time.h" -#include "url/gurl.h" -#include "webkit/common/blob/shareable_file_reference.h" -#include "webkit/common/data_element.h" -#include "webkit/common/storage_common_export.h" - -namespace storage { - -class STORAGE_COMMON_EXPORT BlobData - : public base::RefCounted<BlobData> { - public: - typedef storage::DataElement Item; - - // TODO(michaeln): remove the empty ctor when we fully transition to uuids. - BlobData(); - explicit BlobData(const std::string& uuid); - - void AppendData(const std::string& data) { - AppendData(data.c_str(), data.size()); - } - - void AppendData(const char* data, size_t length); - - void AppendFile(const base::FilePath& file_path, uint64 offset, uint64 length, - const base::Time& expected_modification_time); - void AppendBlob(const std::string& uuid, uint64 offset, uint64 length); - void AppendFileSystemFile(const GURL& url, uint64 offset, uint64 length, - const base::Time& expected_modification_time); - - void AttachShareableFileReference(ShareableFileReference* reference) { - shareable_files_.push_back(reference); - } - - const std::string& uuid() const { return uuid_; } - const std::vector<Item>& items() const { return items_; } - const std::string& content_type() const { return content_type_; } - void set_content_type(const std::string& content_type) { - content_type_ = content_type; - } - - const std::string& content_disposition() const { - return content_disposition_; - } - void set_content_disposition(const std::string& content_disposition) { - content_disposition_ = content_disposition; - } - - int64 GetMemoryUsage() const; - - private: - friend class base::RefCounted<BlobData>; - virtual ~BlobData(); - - std::string uuid_; - std::string content_type_; - std::string content_disposition_; - std::vector<Item> items_; - std::vector<scoped_refptr<ShareableFileReference> > shareable_files_; - - DISALLOW_COPY_AND_ASSIGN(BlobData); -}; - -#if defined(UNIT_TEST) -inline bool operator==(const BlobData& a, const BlobData& b) { - if (a.content_type() != b.content_type()) - return false; - if (a.content_disposition() != b.content_disposition()) - return false; - if (a.items().size() != b.items().size()) - return false; - for (size_t i = 0; i < a.items().size(); ++i) { - if (a.items()[i] != b.items()[i]) - return false; - } - return true; -} - -inline bool operator!=(const BlobData& a, const BlobData& b) { - return !(a == b); -} -#endif // defined(UNIT_TEST) - -} // namespace storage - -#endif // WEBKIT_COMMON_BLOB_BLOB_DATA_H_ +#include "storage/common/blob/blob_data.h" diff --git a/webkit/common/blob/scoped_file.h b/webkit/common/blob/scoped_file.h index 78e592e..027ab3b 100644 --- a/webkit/common/blob/scoped_file.h +++ b/webkit/common/blob/scoped_file.h @@ -1,94 +1,5 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Copyright 2014 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. -#ifndef WEBKIT_COMMON_BLOB_SCOPED_FILE_H_ -#define WEBKIT_COMMON_BLOB_SCOPED_FILE_H_ - -#include <map> - -#include "base/callback_forward.h" -#include "base/files/file_path.h" -#include "base/memory/ref_counted.h" -#include "base/move.h" -#include "webkit/common/storage_common_export.h" - -namespace base { -class TaskRunner; -} - -namespace storage { - -// A scoped reference for a FilePath that can optionally schedule the file -// to be deleted and/or to notify a consumer when it is going to be scoped out. -// This class supports move semantics, i.e. consumers can call Pass() to -// pass the ownership of ScopedFile. -// -// TODO(kinuko): Probably this can be moved under base or somewhere more -// common place. -class STORAGE_COMMON_EXPORT ScopedFile { - // To support destructive assignment from an l-value assignment. - // This provides Pass() method which creates an r-value for the current - // instance. (See base/move.h for details) - MOVE_ONLY_TYPE_FOR_CPP_03(ScopedFile, RValue) - - public: - typedef base::Callback<void(const base::FilePath&)> ScopeOutCallback; - typedef std::pair<ScopeOutCallback, scoped_refptr<base::TaskRunner> > - ScopeOutCallbackPair; - typedef std::vector<ScopeOutCallbackPair> ScopeOutCallbackList; - - enum ScopeOutPolicy { - DELETE_ON_SCOPE_OUT, - DONT_DELETE_ON_SCOPE_OUT, - }; - - ScopedFile(); - - // |file_task_runner| is used to schedule a file deletion if |policy| - // is DELETE_ON_SCOPE_OUT. - ScopedFile(const base::FilePath& path, - ScopeOutPolicy policy, - const scoped_refptr<base::TaskRunner>& file_task_runner); - - // Move constructor and operator. The data of r-value will be transfered - // in a destructive way. (See base/move.h) - ScopedFile(RValue other); - ScopedFile& operator=(RValue rhs) { - MoveFrom(*rhs.object); - return *this; - } - - ~ScopedFile(); - - // The |callback| is fired on |callback_runner| when the final reference - // of this instance is released. - // If release policy is DELETE_ON_SCOPE_OUT the - // callback task(s) is/are posted before the deletion is scheduled. - void AddScopeOutCallback(const ScopeOutCallback& callback, - base::TaskRunner* callback_runner); - - // The full file path. - const base::FilePath& path() const { return path_; } - - // Releases the file. After calling this, this instance will hold - // an empty file path and scoping out won't make any file deletion - // or callback dispatch. (If an owned pointer is attached to any of - // callbacks the pointer will be deleted.) - base::FilePath Release(); - - void Reset(); - - private: - // Performs destructive move from |other| to this. - void MoveFrom(ScopedFile& other); - - base::FilePath path_; - ScopeOutPolicy scope_out_policy_; - scoped_refptr<base::TaskRunner> file_task_runner_; - ScopeOutCallbackList scope_out_callbacks_; -}; - -} // namespace storage - -#endif // WEBKIT_COMMON_BLOB_SCOPED_FILE_H_ +#include "storage/common/blob/scoped_file.h" diff --git a/webkit/common/blob/shareable_file_reference.h b/webkit/common/blob/shareable_file_reference.h index 2e011f4..5702067 100644 --- a/webkit/common/blob/shareable_file_reference.h +++ b/webkit/common/blob/shareable_file_reference.h @@ -1,74 +1,5 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2014 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. -#ifndef WEBKIT_COMMON_BLOB_SHAREABLE_FILE_REFERENCE_H_ -#define WEBKIT_COMMON_BLOB_SHAREABLE_FILE_REFERENCE_H_ - -#include <vector> - -#include "webkit/common/blob/scoped_file.h" - -namespace storage { - -// ShareableFileReference allows consumers to share FileReference for the -// same path if it already exists in its internal map. -// This class is non-thread-safe and all methods must be called on a single -// thread. -class STORAGE_COMMON_EXPORT ShareableFileReference - : public base::RefCounted<ShareableFileReference> { - public: - typedef ScopedFile::ScopeOutCallback FinalReleaseCallback; - - enum FinalReleasePolicy { - DELETE_ON_FINAL_RELEASE = ScopedFile::DELETE_ON_SCOPE_OUT, - DONT_DELETE_ON_FINAL_RELEASE = ScopedFile::DONT_DELETE_ON_SCOPE_OUT, - }; - - // Returns a ShareableFileReference for the given path, if no reference - // for this path exists returns NULL. - static scoped_refptr<ShareableFileReference> Get(const base::FilePath& path); - - // Returns a ShareableFileReference for the given path, creating a new - // reference if none yet exists. If there's a pre-existing reference for - // the path, the policy parameter of this method is ignored. - static scoped_refptr<ShareableFileReference> GetOrCreate( - const base::FilePath& path, - FinalReleasePolicy policy, - base::TaskRunner* file_task_runner); - - // Returns a ShareableFileReference for the given path of the |scoped_file|, - // creating a new reference if none yet exists. The ownership of |scoped_file| - // is passed to this reference. - // If there's a pre-existing reference for the path, the scope out policy - // and scope-out-callbacks of the given |scoped_file| is ignored. - // If the given scoped_file has an empty path (e.g. maybe already - // released) this returns NULL reference. - // - // TODO(kinuko): Make sure if this behavior is ok, we could alternatively - // merge callbacks to the existing one. - static scoped_refptr<ShareableFileReference> GetOrCreate( - ScopedFile scoped_file); - - // The full file path. - const base::FilePath& path() const { return scoped_file_.path(); } - - // The |callback| is fired when the final reference of this instance - // is released. If release policy is DELETE_ON_FINAL_RELEASE the - // callback task(s) is/are posted before the deletion is scheduled. - void AddFinalReleaseCallback(const FinalReleaseCallback& callback); - - private: - friend class base::RefCounted<ShareableFileReference>; - - ShareableFileReference(ScopedFile scoped_file); - ~ShareableFileReference(); - - ScopedFile scoped_file_; - - DISALLOW_COPY_AND_ASSIGN(ShareableFileReference); -}; - -} // namespace storage - -#endif // WEBKIT_COMMON_BLOB_SHAREABLE_FILE_REFERENCE_H_ +#include "storage/common/blob/shareable_file_reference.h" diff --git a/webkit/common/data_element.h b/webkit/common/data_element.h index 33c5c1b..88e0e75 100644 --- a/webkit/common/data_element.h +++ b/webkit/common/data_element.h @@ -1,127 +1,5 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. +// Copyright 2014 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. -#ifndef WEBKIT_COMMON_DATA_ELEMENT_H_ -#define WEBKIT_COMMON_DATA_ELEMENT_H_ - -#include <string> -#include <vector> - -#include "base/basictypes.h" -#include "base/files/file_path.h" -#include "base/logging.h" -#include "base/time/time.h" -#include "url/gurl.h" -#include "webkit/common/webkit_common_export.h" - -namespace storage { - -// Represents a base Web data element. This could be either one of -// bytes, file or blob data. -class WEBKIT_COMMON_EXPORT DataElement { - public: - enum Type { - TYPE_UNKNOWN = -1, - TYPE_BYTES, - TYPE_FILE, - TYPE_BLOB, - TYPE_FILE_FILESYSTEM, - }; - - DataElement(); - ~DataElement(); - - Type type() const { return type_; } - const char* bytes() const { return bytes_ ? bytes_ : &buf_[0]; } - const base::FilePath& path() const { return path_; } - const GURL& filesystem_url() const { return filesystem_url_; } - const std::string& blob_uuid() const { return blob_uuid_; } - uint64 offset() const { return offset_; } - uint64 length() const { return length_; } - const base::Time& expected_modification_time() const { - return expected_modification_time_; - } - - // Sets TYPE_BYTES data. This copies the given data into the element. - void SetToBytes(const char* bytes, int bytes_len) { - type_ = TYPE_BYTES; - buf_.assign(bytes, bytes + bytes_len); - length_ = buf_.size(); - } - - // Sets TYPE_BYTES data. This does NOT copy the given data and the caller - // should make sure the data is alive when this element is accessed. - void SetToSharedBytes(const char* bytes, int bytes_len) { - type_ = TYPE_BYTES; - bytes_ = bytes; - length_ = bytes_len; - } - - // Sets TYPE_FILE data. - void SetToFilePath(const base::FilePath& path) { - SetToFilePathRange(path, 0, kuint64max, base::Time()); - } - - // Sets TYPE_BLOB data. - void SetToBlob(const std::string& uuid) { - SetToBlobRange(uuid, 0, kuint64max); - } - - // Sets TYPE_FILE data with range. - void SetToFilePathRange(const base::FilePath& path, - uint64 offset, uint64 length, - const base::Time& expected_modification_time); - - // Sets TYPE_BLOB data with range. - void SetToBlobRange(const std::string& blob_uuid, - uint64 offset, uint64 length); - - // Sets TYPE_FILE_FILESYSTEM with range. - void SetToFileSystemUrlRange(const GURL& filesystem_url, - uint64 offset, uint64 length, - const base::Time& expected_modification_time); - - private: - Type type_; - std::vector<char> buf_; // For TYPE_BYTES. - const char* bytes_; // For TYPE_BYTES. - base::FilePath path_; // For TYPE_FILE. - GURL filesystem_url_; // For TYPE_FILE_FILESYSTEM. - std::string blob_uuid_; - uint64 offset_; - uint64 length_; - base::Time expected_modification_time_; -}; - -#if defined(UNIT_TEST) -inline bool operator==(const DataElement& a, const DataElement& b) { - if (a.type() != b.type() || - a.offset() != b.offset() || - a.length() != b.length()) - return false; - switch (a.type()) { - case DataElement::TYPE_BYTES: - return memcmp(a.bytes(), b.bytes(), b.length()) == 0; - case DataElement::TYPE_FILE: - return a.path() == b.path() && - a.expected_modification_time() == b.expected_modification_time(); - case DataElement::TYPE_BLOB: - return a.blob_uuid() == b.blob_uuid(); - case DataElement::TYPE_FILE_FILESYSTEM: - return a.filesystem_url() == b.filesystem_url(); - case DataElement::TYPE_UNKNOWN: - NOTREACHED(); - return false; - } - return false; -} - -inline bool operator!=(const DataElement& a, const DataElement& b) { - return !(a == b); -} -#endif // defined(UNIT_TEST) - -} // namespace storage - -#endif // WEBKIT_COMMON_DATA_ELEMENT_H_ +#include "storage/common/data_element.h" diff --git a/webkit/common/database/database_connections.h b/webkit/common/database/database_connections.h index 88421cb..b847909 100644 --- a/webkit/common/database/database_connections.h +++ b/webkit/common/database/database_connections.h @@ -1,99 +1,5 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright 2014 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. -#ifndef WEBKIT_COMMON_DATABASE_DATABASE_CONNECTIONS_H_ -#define WEBKIT_COMMON_DATABASE_DATABASE_CONNECTIONS_H_ - -#include <map> -#include <string> -#include <vector> - -#include "base/memory/ref_counted.h" -#include "base/strings/string16.h" -#include "base/synchronization/lock.h" -#include "webkit/common/storage_common_export.h" - -namespace base { -class MessageLoopProxy; -} - -namespace storage { - -class STORAGE_COMMON_EXPORT DatabaseConnections { - public: - DatabaseConnections(); - ~DatabaseConnections(); - - bool IsEmpty() const; - bool IsDatabaseOpened(const std::string& origin_identifier, - const base::string16& database_name) const; - bool IsOriginUsed(const std::string& origin_identifier) const; - - // Returns true if this is the first connection. - bool AddConnection(const std::string& origin_identifier, - const base::string16& database_name); - - // Returns true if the last connection was removed. - bool RemoveConnection(const std::string& origin_identifier, - const base::string16& database_name); - - void RemoveAllConnections(); - void RemoveConnections( - const DatabaseConnections& connections, - std::vector<std::pair<std::string, base::string16> >* closed_dbs); - - // Database sizes can be kept only if IsDatabaseOpened returns true. - int64 GetOpenDatabaseSize(const std::string& origin_identifier, - const base::string16& database_name) const; - void SetOpenDatabaseSize(const std::string& origin_identifier, - const base::string16& database_name, - int64 size); - - // Returns a list of the connections, <origin_id, name>. - void ListConnections( - std::vector<std::pair<std::string, base::string16> > *list) const; - - private: - // Mapping from name to <openCount, size> - typedef std::map<base::string16, std::pair<int, int64> > DBConnections; - typedef std::map<std::string, DBConnections> OriginConnections; - mutable OriginConnections connections_; // mutable for GetOpenDatabaseSize - - // Returns true if the last connection was removed. - bool RemoveConnectionsHelper(const std::string& origin_identifier, - const base::string16& database_name, - int num_connections); -}; - -// A wrapper class that provides thread-safety and the -// ability to wait until all connections have closed. -// Intended for use in renderer processes. -class STORAGE_COMMON_EXPORT DatabaseConnectionsWrapper - : public base::RefCountedThreadSafe<DatabaseConnectionsWrapper> { - public: - DatabaseConnectionsWrapper(); - - // The Wait and Has methods should only be called on the - // main thread (the thread on which the wrapper is constructed). - void WaitForAllDatabasesToClose(); - bool HasOpenConnections(); - - // Add and Remove may be called on any thread. - void AddOpenConnection(const std::string& origin_identifier, - const base::string16& database_name); - void RemoveOpenConnection(const std::string& origin_identifier, - const base::string16& database_name); - private: - ~DatabaseConnectionsWrapper(); - friend class base::RefCountedThreadSafe<DatabaseConnectionsWrapper>; - - bool waiting_for_dbs_to_close_; - base::Lock open_connections_lock_; - DatabaseConnections open_connections_; - scoped_refptr<base::MessageLoopProxy> main_thread_; -}; - -} // namespace storage - -#endif // WEBKIT_COMMON_DATABASE_DATABASE_CONNECTIONS_H_ +#include "storage/common/database/database_connections.h" diff --git a/webkit/common/database/database_identifier.h b/webkit/common/database/database_identifier.h index b72c02b..38e2777 100644 --- a/webkit/common/database/database_identifier.h +++ b/webkit/common/database/database_identifier.h @@ -1,54 +1,5 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. +// Copyright 2014 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. -#ifndef WEBKIT_COMMON_DATABASE_DATABASE_IDENTIFIER_H_ -#define WEBKIT_COMMON_DATABASE_DATABASE_IDENTIFIER_H_ - -#include <string> - -#include "base/basictypes.h" -#include "base/strings/string_piece.h" -#include "url/gurl.h" -#include "webkit/common/storage_common_export.h" - -namespace storage { - -STORAGE_COMMON_EXPORT std::string GetIdentifierFromOrigin( - const GURL& origin); -STORAGE_COMMON_EXPORT GURL GetOriginFromIdentifier( - const std::string& identifier); - -class STORAGE_COMMON_EXPORT DatabaseIdentifier { - public: - static const DatabaseIdentifier UniqueFileIdentifier(); - static DatabaseIdentifier CreateFromOrigin(const GURL& origin); - static DatabaseIdentifier Parse(const std::string& identifier); - ~DatabaseIdentifier(); - - std::string ToString() const; - GURL ToOrigin() const; - - std::string scheme() const { return scheme_; } - std::string hostname() const { return hostname_; } - int port() const { return port_; } - bool is_unique() const { return is_unique_; } - - private: - DatabaseIdentifier(); - DatabaseIdentifier(const std::string& scheme, - const std::string& hostname, - int port, - bool is_unique, - bool is_file); - - std::string scheme_; - std::string hostname_; - int port_; - bool is_unique_; - bool is_file_; -}; - -} // namespace storage - -#endif // WEBKIT_COMMON_DATABASE_DATABASE_IDENTIFIER_H_ +#include "storage/common/database/database_identifier.h" diff --git a/webkit/common/fileapi/directory_entry.h b/webkit/common/fileapi/directory_entry.h index 359fce4..536fe6f 100644 --- a/webkit/common/fileapi/directory_entry.h +++ b/webkit/common/fileapi/directory_entry.h @@ -1,38 +1,5 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. +// Copyright 2014 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. -#ifndef WEBKIT_COMMON_FILEAPI_DIRECTORY_ENTRY_H_ -#define WEBKIT_COMMON_FILEAPI_DIRECTORY_ENTRY_H_ - -#include <string> - -#include "base/basictypes.h" -#include "base/files/file_path.h" -#include "base/time/time.h" -#include "webkit/common/storage_common_export.h" - -namespace storage { - -// Holds metadata for file or directory entry. -struct STORAGE_COMMON_EXPORT DirectoryEntry { - enum DirectoryEntryType { - FILE, - DIRECTORY, - }; - - DirectoryEntry(); - DirectoryEntry(const std::string& name, - DirectoryEntryType type, - int64 size, - const base::Time& last_modified_time); - - base::FilePath::StringType name; - bool is_directory; - int64 size; - base::Time last_modified_time; -}; - -} // namespace storage - -#endif // WEBKIT_COMMON_FILEAPI_DIRECTORY_ENTRY_H_ +#include "storage/common/fileapi/directory_entry.h" diff --git a/webkit/common/fileapi/file_system_info.h b/webkit/common/fileapi/file_system_info.h index eefe55e..5e20860 100644 --- a/webkit/common/fileapi/file_system_info.h +++ b/webkit/common/fileapi/file_system_info.h @@ -1,33 +1,5 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. +// Copyright 2014 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. -#ifndef WEBKIT_COMMON_FILEAPI_FILE_SYSTEM_INFO_H_ -#define WEBKIT_COMMON_FILEAPI_FILE_SYSTEM_INFO_H_ - -#include <string> - -#include "url/gurl.h" -#include "webkit/common/fileapi/file_system_types.h" -#include "webkit/common/storage_common_export.h" - -namespace storage { - -// This struct is used to send the necessary information for Blink to create a -// DOMFileSystem. Since Blink side only uses mount_type (rather than -// detailed/cracked filesystem type) this only contains mount_type but not type. -struct STORAGE_COMMON_EXPORT FileSystemInfo { - FileSystemInfo(); - FileSystemInfo(const std::string& filesystem_name, - const GURL& root_url, - storage::FileSystemType mount_type); - ~FileSystemInfo(); - - std::string name; - GURL root_url; - storage::FileSystemType mount_type; -}; - -} // namespace storage - -#endif // WEBKIT_COMMON_FILEAPI_FILE_SYSTEM_INFO_H_ +#include "storage/common/fileapi/file_system_info.h" diff --git a/webkit/common/fileapi/file_system_mount_option.h b/webkit/common/fileapi/file_system_mount_option.h index a2ab732..fc7b325 100644 --- a/webkit/common/fileapi/file_system_mount_option.h +++ b/webkit/common/fileapi/file_system_mount_option.h @@ -1,37 +1,5 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. +// Copyright 2014 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. -#ifndef WEBKIT_COMMON_FILEAPI_FILE_SYSTEM_MOUNT_OPTION_H_ -#define WEBKIT_COMMON_FILEAPI_FILE_SYSTEM_MOUNT_OPTION_H_ - -namespace storage { - -// Option for specifying if disk sync operation is wanted after copying. -enum CopySyncOption { - COPY_SYNC_OPTION_NO_SYNC, - COPY_SYNC_OPTION_SYNC, -}; - -// Conveys options for a mounted file systems. -class FileSystemMountOption { - public: - // Constructs with the default options. - FileSystemMountOption() - : copy_sync_option_(COPY_SYNC_OPTION_NO_SYNC) {} - - // Constructs with the specified component. - explicit FileSystemMountOption(CopySyncOption copy_sync_option) - : copy_sync_option_(copy_sync_option) {} - - CopySyncOption copy_sync_option() const { - return copy_sync_option_; - } - - private: - CopySyncOption copy_sync_option_; -}; - -} // namespace storage - -#endif // WEBKIT_COMMON_FILEAPI_FILE_SYSTEM_MOUNT_OPTION_H_ +#include "storage/common/fileapi/file_system_mount_option.h" diff --git a/webkit/common/fileapi/file_system_types.h b/webkit/common/fileapi/file_system_types.h index 8a56a8b..ff8e0fd 100644 --- a/webkit/common/fileapi/file_system_types.h +++ b/webkit/common/fileapi/file_system_types.h @@ -1,137 +1,5 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2014 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. -#ifndef WEBKIT_COMMON_FILEAPI_FILE_SYSTEM_TYPES_H_ -#define WEBKIT_COMMON_FILEAPI_FILE_SYSTEM_TYPES_H_ - -#include "third_party/WebKit/public/platform/WebFileSystemType.h" - -namespace storage { - -enum FileSystemType { - // Indicates uninitialized or invalid filesystem type. - kFileSystemTypeUnknown = -1, - - // ------------------------------------------------------------------------ - // Public FileSystem types, that are embedded in filesystem: URL and exposed - // to WebKit/renderer. Both Chrome and WebKit know how to handle these types. - - // Following two types are for TEMPORARY or PERSISTENT filesystems that - // can be used by webapps via standard app-facing API - // as defined in File API: Directories and System. - // http://www.w3.org/TR/file-system-api/#temporary-vs.-persistent-storage - // They are sandboxed filesystems; all the files in the filesystems are - // placed under the profile directory with path obfuscation and quota - // enforcement. - kFileSystemTypeTemporary = blink::WebFileSystemTypeTemporary, - kFileSystemTypePersistent = blink::WebFileSystemTypePersistent, - - // Indicates non-sandboxed isolated filesystem. - kFileSystemTypeIsolated = blink::WebFileSystemTypeIsolated, - - // Indicates filesystems that are mounted externally via - // ExternalMountPoints with a well-known mount name. The mounted - // filesystems can be sandboxed or non-sandboxed. (E.g. Chrome OS mounts - // non-sandboxed removable media folder with a name 'removable', while - // chrome.syncFileSystem mounts a sandboxed filesystem with a name - // 'syncfs'.) - kFileSystemTypeExternal = blink::WebFileSystemTypeExternal, - - // ------------------------------------------------------------------------ - // Marks the beginning of internal type enum. (This is not the actual fs type) - kFileSystemInternalTypeEnumStart = 99, - - // Private FileSystem types, that should not appear in filesystem: URL as - // WebKit has no idea how to handle those types. - // - // One can register (mount) a new file system with a private file system type - // using IsolatedContext. Files in such file systems can be accessed via - // either Isolated or External public file system types (depending on - // how the file system is registered). - // See the comments for IsolatedContext and/or FileSystemURL for more details. - - // Should be used only for testing. - kFileSystemTypeTest, - - // Indicates a local filesystem where we can access files using native - // local path. - kFileSystemTypeNativeLocal, - - // Indicates a local filesystem where we can access files using native - // local path, but with restricted access. - // Restricted native local file system is in read-only mode. - kFileSystemTypeRestrictedNativeLocal, - - // Indicates a transient, isolated file system for dragged files (which could - // contain multiple dragged paths in the virtual root). - kFileSystemTypeDragged, - - // Indicates media filesystem which we can access with same manner to - // regular filesystem. - kFileSystemTypeNativeMedia, - - // Indicates media filesystem to which we need special protocol to access, - // such as MTP or PTP. - kFileSystemTypeDeviceMedia, - - // Indicates a Picasa virtual filesystem provided by Media Galleries API. - kFileSystemTypePicasa, - - // Indicates a synthetic iTunes filesystem. - kFileSystemTypeItunes, - - // Indicates a synthetic iPhoto filesystem. - kFileSystemTypeIphoto, - - // Indicates a Drive filesystem which provides access to Google Drive. - kFileSystemTypeDrive, - - // Indicates a Syncable sandboxed filesystem which can be backed by a - // cloud storage service. - kFileSystemTypeSyncable, - - // Indicates a special filesystem type for internal file sync operation - // for Syncable sandboxed filesystems. The file system is overlayed, i.e. - // points to the same sandboxed filesystem as that of kFileSystemTypeSyncable, - // but the changes made with this filesystem type are not recorded for - // further sync. - kFileSystemTypeSyncableForInternalSync, - - // Indicates an external filesystem accessible by file paths from platform - // Apps. As of writing, on non Chrome OS platform, this is merely a - // kFileSystemTypeNativeLocal. On Chrome OS, the path is parsed by - // the handlers of kFileSystemTypeExternal. - kFileSystemTypeNativeForPlatformApp, - - // Indicates an isolated filesystem which is supposed to contain one - // temporary which is supposed to go away when the last reference of - // its snapshot is dropped. - // This type is useful for creating a blob reference for a temporary - // file which must go away when the blob's last reference is dropped. - kFileSystemTypeForTransientFile, - - // Sandboxed private filesystem. This filesystem cannot be opened - // via regular OpenFileSystem, and provides private filesystem space for - // given identifier in each origin. - kFileSystemTypePluginPrivate, - - // A filesystem that is mounted via the Privet storage protocol. - kFileSystemTypeCloudDevice, - - // A filesystem that is mounted via the FileSystemProvider API. - kFileSystemTypeProvided, - - // A media filesystem such as MTP or PTP, mounted as a file storage not - // limited to media files. - kFileSystemTypeDeviceMediaAsFileStorage, - - // -------------------------------------------------------------------- - // Marks the end of internal type enum. (This is not the actual fs type) - // New internal filesystem types must be added above this line. - kFileSystemInternalTypeEnumEnd, -}; - -} // namespace storage - -#endif // WEBKIT_COMMON_FILEAPI_FILE_SYSTEM_TYPES_H_ +#include "storage/common/fileapi/file_system_types.h" diff --git a/webkit/common/fileapi/file_system_util.h b/webkit/common/fileapi/file_system_util.h index 4da856d..c5c0efa 100644 --- a/webkit/common/fileapi/file_system_util.h +++ b/webkit/common/fileapi/file_system_util.h @@ -1,182 +1,5 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2014 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. -#ifndef WEBKIT_COMMON_FILEAPI_FILE_SYSTEM_UTIL_H_ -#define WEBKIT_COMMON_FILEAPI_FILE_SYSTEM_UTIL_H_ - -#include <string> -#include <vector> - -#include "base/files/file.h" -#include "base/files/file_path.h" -#include "third_party/WebKit/public/platform/WebFileError.h" -#include "third_party/WebKit/public/platform/WebFileSystemType.h" -#include "webkit/common/fileapi/file_system_info.h" -#include "webkit/common/fileapi/file_system_types.h" -#include "webkit/common/quota/quota_types.h" -#include "webkit/common/storage_common_export.h" - -class GURL; - -namespace storage { - -STORAGE_COMMON_EXPORT extern const char kPersistentDir[]; -STORAGE_COMMON_EXPORT extern const char kTemporaryDir[]; -STORAGE_COMMON_EXPORT extern const char kExternalDir[]; -STORAGE_COMMON_EXPORT extern const char kIsolatedDir[]; -STORAGE_COMMON_EXPORT extern const char kTestDir[]; - -class STORAGE_COMMON_EXPORT VirtualPath { - public: - static const base::FilePath::CharType kRoot[]; - static const base::FilePath::CharType kSeparator; - - // Use this instead of base::FilePath::BaseName when operating on virtual - // paths. FilePath::BaseName will get confused by ':' on Windows when it - // looks like a drive letter separator; this will treat it as just another - // character. - static base::FilePath BaseName(const base::FilePath& virtual_path); - - // Use this instead of base::FilePath::DirName when operating on virtual - // paths. - static base::FilePath DirName(const base::FilePath& virtual_path); - - // Likewise, use this instead of base::FilePath::GetComponents when - // operating on virtual paths. - // Note that this assumes very clean input, with no leading slash, and - // it will not evaluate '..' components. - static void GetComponents( - const base::FilePath& path, - std::vector<base::FilePath::StringType>* components); - - static void GetComponentsUTF8Unsafe( - const base::FilePath& path, std::vector<std::string>* components); - - // Returns a path name ensuring that it begins with kRoot and all path - // separators are forward slashes /. - static base::FilePath::StringType GetNormalizedFilePath( - const base::FilePath& path); - - // Returns true if the given path begins with kRoot. - static bool IsAbsolute(const base::FilePath::StringType& path); - - // Returns true if the given path points to the root. - static bool IsRootPath(const base::FilePath& path); -}; - -// Parses filesystem scheme |url| into uncracked file system URL components. -// Example: For a URL 'filesystem:http://foo.com/temporary/foo/bar', -// |origin_url| is set to 'http://foo.com', |type| is set to -// kFileSystemTypeTemporary, and |virtual_path| is set to 'foo/bar'. -STORAGE_COMMON_EXPORT bool ParseFileSystemSchemeURL( - const GURL& url, - GURL* origin_url, - FileSystemType* type, - base::FilePath* virtual_path); - -// Returns the root URI of the filesystem that can be specified by a pair of -// |origin_url| and |type|. The returned URI can be used as a root path -// of the filesystem (e.g. <returned_URI> + "/relative/path" will compose -// a path pointing to the entry "/relative/path" in the filesystem). -// -// For Isolated filesystem this returns the 'common' root part, e.g. -// returns URL without the filesystem ID. -// -// |type| needs to be public type as the returned URI is given to the renderer. -STORAGE_COMMON_EXPORT GURL GetFileSystemRootURI(const GURL& origin_url, - FileSystemType type); - -// Returns the name for the filesystem that is specified by a pair of -// |origin_url| and |type|. -// (The name itself is neither really significant nor a formal identifier -// but can be read as the .name field of the returned FileSystem object -// as a user-friendly name in the javascript layer). -// -// |type| needs to be public type as the returned name is given to the renderer. -// -// Example: -// The name for a TEMPORARY filesystem of "http://www.example.com:80/" -// should look like: "http_www.example.host_80:temporary" -STORAGE_COMMON_EXPORT std::string -GetFileSystemName(const GURL& origin_url, FileSystemType type); - -// Converts FileSystemType |type| to/from the StorageType |storage_type| that -// is used for the unified quota system. -// (Basically this naively maps TEMPORARY storage type to TEMPORARY filesystem -// type, PERSISTENT storage type to PERSISTENT filesystem type and vice versa.) -STORAGE_COMMON_EXPORT FileSystemType - QuotaStorageTypeToFileSystemType(storage::StorageType storage_type); - -STORAGE_COMMON_EXPORT storage::StorageType - FileSystemTypeToQuotaStorageType(FileSystemType type); - -// Returns the string representation of the given filesystem |type|. -// Returns an empty string if the |type| is invalid. -STORAGE_COMMON_EXPORT std::string -GetFileSystemTypeString(FileSystemType type); - -// Sets type to FileSystemType enum that corresponds to the string name. -// Returns false if the |type_string| is invalid. -STORAGE_COMMON_EXPORT bool GetFileSystemPublicType( - std::string type_string, - blink::WebFileSystemType* type); - -// Encodes |file_path| to a string. -// Following conditions should be held: -// - StringToFilePath(FilePathToString(path)) == path -// - StringToFilePath(FilePathToString(path) + "/" + "SubDirectory") == -// path.AppendASCII("SubDirectory"); -// -// TODO(tzik): Replace CreateFilePath and FilePathToString in -// third_party/leveldatabase/env_chromium.cc with them. -STORAGE_COMMON_EXPORT std::string FilePathToString( - const base::FilePath& file_path); - -// Decode a file path from |file_path_string|. -STORAGE_COMMON_EXPORT base::FilePath StringToFilePath( - const std::string& file_path_string); - -// File error conversion -STORAGE_COMMON_EXPORT blink::WebFileError -FileErrorToWebFileError(base::File::Error error_code); - -// Generate a file system name for the given arguments. Should only be used by -// platform apps. -STORAGE_COMMON_EXPORT std::string GetIsolatedFileSystemName( - const GURL& origin_url, - const std::string& filesystem_id); - -// Find the file system id from |filesystem_name|. Should only be used by -// platform apps. This function will return false if the file system name is -// not of the form {origin}:Isolated_{id}, and will also check that there is an -// origin and id present. It will not check that the origin or id are valid. -STORAGE_COMMON_EXPORT bool CrackIsolatedFileSystemName( - const std::string& filesystem_name, - std::string* filesystem_id); - -// Validates the given isolated file system id. -STORAGE_COMMON_EXPORT bool ValidateIsolatedFileSystemId( - const std::string& filesystem_id); - -// Returns the root URI for an isolated filesystem for origin |origin_url| -// and |filesystem_id|. If the |optional_root_name| is given the resulting -// root URI will point to the subfolder within the isolated filesystem. -STORAGE_COMMON_EXPORT std::string GetIsolatedFileSystemRootURIString( - const GURL& origin_url, - const std::string& filesystem_id, - const std::string& optional_root_name); - -// Returns the root URI for an external filesystem for origin |origin_url| -// and |mount_name|. -STORAGE_COMMON_EXPORT std::string GetExternalFileSystemRootURIString( - const GURL& origin_url, - const std::string& mount_name); - -// Translates the net::Error to base::File::Error. -STORAGE_COMMON_EXPORT base::File::Error -NetErrorToFileError(int error); - -} // namespace storage - -#endif // WEBKIT_COMMON_FILEAPI_FILE_SYSTEM_UTIL_H_ +#include "storage/common/fileapi/file_system_util.h" diff --git a/webkit/common/quota/quota_status_code.h b/webkit/common/quota/quota_status_code.h index bfd6ece..b9e239d 100644 --- a/webkit/common/quota/quota_status_code.h +++ b/webkit/common/quota/quota_status_code.h @@ -1,28 +1,5 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. +// Copyright 2014 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. -#ifndef WEBKIT_COMMON_QUOTA_QUOTA_STATUS_CODE_H_ -#define WEBKIT_COMMON_QUOTA_QUOTA_STATUS_CODE_H_ - -#include "third_party/WebKit/public/platform/WebStorageQuotaError.h" -#include "webkit/common/storage_common_export.h" - -namespace storage { - -enum QuotaStatusCode { - kQuotaStatusOk = 0, - kQuotaErrorNotSupported = blink::WebStorageQuotaErrorNotSupported, - kQuotaErrorInvalidModification = - blink::WebStorageQuotaErrorInvalidModification, - kQuotaErrorInvalidAccess = blink::WebStorageQuotaErrorInvalidAccess, - kQuotaErrorAbort = blink::WebStorageQuotaErrorAbort, - kQuotaStatusUnknown = -1, -}; - -STORAGE_COMMON_EXPORT const char* QuotaStatusCodeToString( - QuotaStatusCode status); - -} // namespace storage - -#endif // WEBKIT_COMMON_QUOTA_QUOTA_STATUS_CODE_H_ +#include "storage/common/quota/quota_status_code.h" diff --git a/webkit/common/quota/quota_types.h b/webkit/common/quota/quota_types.h index fa69b29..36c9ba4 100644 --- a/webkit/common/quota/quota_types.h +++ b/webkit/common/quota/quota_types.h @@ -1,29 +1,5 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. +// Copyright 2014 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. -#ifndef WEBKIT_COMMON_QUOTA_QUOTA_TYPES_H_ -#define WEBKIT_COMMON_QUOTA_QUOTA_TYPES_H_ - -#include "webkit/common/quota/quota_status_code.h" - -namespace storage { - -enum StorageType { - kStorageTypeTemporary, - kStorageTypePersistent, - kStorageTypeSyncable, - kStorageTypeQuotaNotManaged, - kStorageTypeUnknown, - kStorageTypeLast = kStorageTypeUnknown -}; - -enum QuotaLimitType { - kQuotaLimitTypeUnknown, - kQuotaLimitTypeLimited, - kQuotaLimitTypeUnlimited, -}; - -} // namespace storage - -#endif // WEBKIT_COMMON_QUOTA_QUOTA_TYPES_H_ +#include "storage/common/quota/quota_types.h" diff --git a/webkit/common/webkit_common.gyp b/webkit/common/webkit_common.gyp deleted file mode 100644 index 89a5a34..0000000 --- a/webkit/common/webkit_common.gyp +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright 2013 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. - -{ - 'variables': { - 'enable_wexit_time_destructors': 1, - 'chromium_code': 1 - }, - 'targets': [ - { - # GN version: //webkit/common:common", - 'target_name': 'webkit_common', - 'type': '<(component)', - 'defines': [ - 'WEBKIT_COMMON_IMPLEMENTATION', - ], - 'dependencies': [ - '../../base/base.gyp:base', - '../../url/url.gyp:url_lib', - ], - 'sources': [ - 'data_element.cc', - 'data_element.h', - 'webkit_common_export.h', - ], - }, - ], -} diff --git a/webkit/storage_browser.gyp b/webkit/storage_browser.gyp index 71ebcd9..ed08918 100644 --- a/webkit/storage_browser.gyp +++ b/webkit/storage_browser.gyp @@ -18,11 +18,10 @@ '<(DEPTH)/base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations', '<(DEPTH)/net/net.gyp:net', '<(DEPTH)/sql/sql.gyp:sql', + '<(DEPTH)/storage/storage_common.gyp:storage_common', '<(DEPTH)/third_party/leveldatabase/leveldatabase.gyp:leveldatabase', '<(DEPTH)/third_party/sqlite/sqlite.gyp:sqlite', '<(DEPTH)/url/url.gyp:url_lib', - '<(DEPTH)/webkit/common/webkit_common.gyp:webkit_common', - '<(DEPTH)/webkit/storage_common.gyp:storage_common', ], 'defines': ['STORAGE_BROWSER_IMPLEMENTATION'], 'sources': [ @@ -192,7 +191,7 @@ ], 'dependencies': [ '<(DEPTH)/base/base.gyp:base', - '<(DEPTH)/webkit/storage_common.gyp:storage_common', + '<(DEPTH)/storage/storage_common.gyp:storage_common', 'storage', ], }, |
