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

Side by Side Diff: chrome/browser/media_gallery/media_file_system_registry.cc

Issue 10409084: Media Gallery: Implement a basic version of GetMediaFileSystems(). (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // MediaFileSystemRegistry implementation.
6
7 #include "chrome/browser/media_gallery/media_file_system_registry.h"
8
9 #include <set>
10
11 #include "base/path_service.h"
12 #include "base/sys_string_conversions.h"
13 #include "chrome/common/chrome_paths.h"
14 #include "content/public/browser/browser_thread.h"
15 #include "webkit/fileapi/isolated_context.h"
16
17 namespace chrome {
18
19 static base::LazyInstance<MediaFileSystemRegistry>::Leaky
20 g_media_file_system_registry = LAZY_INSTANCE_INITIALIZER;
21
22 using content::BrowserThread;
23 using fileapi::IsolatedContext;
24
25 // static
26 MediaFileSystemRegistry* MediaFileSystemRegistry::GetInstance() {
27 return g_media_file_system_registry.Pointer();
28 }
29
30 std::vector<MediaFileSystemRegistry::MediaFSIDAndPath>
31 MediaFileSystemRegistry::GetMediaFileSystems() const {
32 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
33 std::vector<MediaFSIDAndPath> results;
34 for (MediaPathToFSIDMap::const_iterator it = media_fs_map_.begin();
35 it != media_fs_map_.end();
36 ++it) {
37 const FilePath path = it->first;
38 const std::string fsid = it->second;
39 results.push_back(std::make_pair(fsid, path));
40 }
41 return results;
42 }
43
44 MediaFileSystemRegistry::MediaFileSystemRegistry() {
45 FilePath pictures_path;
46 if (PathService::Get(chrome::DIR_USER_PICTURES, &pictures_path)) {
47 RegisterPathAsFileSystem(pictures_path);
48 }
49 }
50
51 MediaFileSystemRegistry::~MediaFileSystemRegistry() {
52 }
53
54 void MediaFileSystemRegistry::RegisterPathAsFileSystem(const FilePath& path) {
55 // Sanity checks for |path|.
56 CHECK(path.IsAbsolute());
57 CHECK(!path.ReferencesParent());
58 // Make sure |path| does not refer to '/' on Unix.
59 // TODO(thestig) Check how BaseName() works for say, 'C:\' on Windows.
kinuko 2012/05/24 05:17:05 Ah this is a good point... we may have a problem i
60 CHECK(!path.BaseName().IsAbsolute());
61 CHECK(!path.BaseName().empty());
62
63 std::set<FilePath> fileset;
64 fileset.insert(path);
65 const std::string fsid =
66 IsolatedContext::GetInstance()->RegisterIsolatedFileSystem(fileset);
67 CHECK(!fsid.empty());
68 media_fs_map_.insert(std::make_pair(path, fsid));
69 }
70
71 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698