blob: d83310d425ee7c42e7f17e13930d6268a0b9d77c [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"
9
10namespace fileapi {
11
12FileSystemURL::FileSystemURL()
13 : type_(kFileSystemTypeUnknown), is_valid_(false) {}
14
15FileSystemURL::FileSystemURL(const GURL& url)
16 : type_(kFileSystemTypeUnknown) {
17 is_valid_ = CrackFileSystemURL(url, &origin_, &type_, &path_);
18}
19
20FileSystemURL::FileSystemURL(
21 const GURL& origin,
22 FileSystemType type,
23 const FilePath& path)
24 : origin_(origin),
25 type_(type),
26 path_(path),
27 is_valid_(true) {}
28
29FileSystemURL::~FileSystemURL() {}
30
31std::string FileSystemURL::spec() const {
32 if (!is_valid_)
33 return std::string();
34 return GetFileSystemRootURI(origin_, type_).spec() + "/" +
35 path_.AsUTF8Unsafe();
36}
37
38FileSystemURL FileSystemURL::WithPath(const FilePath& path) const {
39 return FileSystemURL(origin(), type(), path);
40}
41
42bool FileSystemURL::operator==(const FileSystemURL& that) const {
43 return origin_ == that.origin_ &&
44 type_ == that.type_ &&
45 path_ == that.path_ &&
46 is_valid_ == that.is_valid_;
47}
48
49} // namespace fileapi