blob: ab0c2d8f6838d4f6f578ff9c4d8108b8c2be3943 [file] [log] [blame]
[email protected]949f25a2012-06-27 01:53:091// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "webkit/fileapi/file_system_url.h"
6
7#include "webkit/fileapi/file_system_types.h"
8#include "webkit/fileapi/file_system_util.h"
[email protected]d6afd112012-07-25 22:55:049#include "webkit/fileapi/isolated_context.h"
[email protected]949f25a2012-06-27 01:53:0910
11namespace fileapi {
12
13FileSystemURL::FileSystemURL()
14 : type_(kFileSystemTypeUnknown), is_valid_(false) {}
15
16FileSystemURL::FileSystemURL(const GURL& url)
17 : type_(kFileSystemTypeUnknown) {
18 is_valid_ = CrackFileSystemURL(url, &origin_, &type_, &path_);
[email protected]d6afd112012-07-25 22:55:0419 MayCrackIsolatedPath();
[email protected]949f25a2012-06-27 01:53:0920}
21
22FileSystemURL::FileSystemURL(
23 const GURL& origin,
24 FileSystemType type,
25 const FilePath& path)
26 : origin_(origin),
27 type_(type),
28 path_(path),
[email protected]d6afd112012-07-25 22:55:0429 is_valid_(true) {
30 MayCrackIsolatedPath();
31}
[email protected]949f25a2012-06-27 01:53:0932
33FileSystemURL::~FileSystemURL() {}
34
35std::string FileSystemURL::spec() const {
36 if (!is_valid_)
37 return std::string();
38 return GetFileSystemRootURI(origin_, type_).spec() + "/" +
39 path_.AsUTF8Unsafe();
40}
41
42FileSystemURL FileSystemURL::WithPath(const FilePath& path) const {
43 return FileSystemURL(origin(), type(), path);
44}
45
46bool FileSystemURL::operator==(const FileSystemURL& that) const {
47 return origin_ == that.origin_ &&
48 type_ == that.type_ &&
49 path_ == that.path_ &&
[email protected]d6afd112012-07-25 22:55:0450 filesystem_id_ == that.filesystem_id_ &&
[email protected]949f25a2012-06-27 01:53:0951 is_valid_ == that.is_valid_;
52}
53
[email protected]d6afd112012-07-25 22:55:0454void FileSystemURL::MayCrackIsolatedPath() {
55 if (is_valid_ && type_ == kFileSystemTypeIsolated) {
56 // If the type is isolated, crack the path further to get the 'real'
57 // filesystem type and path.
58 is_valid_ = IsolatedContext::GetInstance()->CrackIsolatedPath(
59 path_, &filesystem_id_, &type_, &path_);
60 }
61}
62
[email protected]949f25a2012-06-27 01:53:0963} // namespace fileapi