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

Side by Side Diff: chrome/browser/extensions/api/systeminfo_storage/systeminfo_storage_api.cc

Issue 10824232: Add systeminfo.storage API implementation skeleton (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Add StorageInfoProvder impl on Windows Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 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 #include "chrome/browser/extensions/api/systeminfo_storage/systeminfo_storage_ap i.h"
5
6 #include "base/logging.h"
7 #include "base/json/json_writer.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/string_number_conversions.h"
10 #include "base/string_piece.h"
11 #include "base/values.h"
12 #include "content/public/browser/browser_thread.h"
13 #include "chrome/browser/extensions/extension_service.h"
14 #include "chrome/browser/extensions/api/systeminfo_storage/storage_info_provider .h"
15
16 namespace extensions {
17 using api::experimental_systeminfo_storage::StorageInfo;
18 using api::experimental_systeminfo_storage::StorageUnitInfo;
19 using content::BrowserThread;
20
21 SysteminfoStorageGetFunction::SysteminfoStorageGetFunction() {
22 }
23
24 SysteminfoStorageGetFunction::~SysteminfoStorageGetFunction() {
25 }
26
27 bool SysteminfoStorageGetFunction::RunImpl() {
28 BrowserThread::PostTask(
29 BrowserThread::FILE, FROM_HERE,
30 base::Bind(&SysteminfoStorageGetFunction::WorkOnFileThread, this));
31 return true;
32 }
33
34 void SysteminfoStorageGetFunction::WorkOnFileThread() {
35 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
36 bool success = false;
37 scoped_ptr<StorageInfoProvider> provider(StorageInfoProvider::Create());
38 StorageInfo info;
39 if (provider.get() && provider->GetStorageInfo(&info)) {
40 SetResult(info.ToValue().release());
41 success = true;
42 } else {
43 SetError("Error in querying storage information");
44 }
45
46 // Response the result on UI thread.
47 BrowserThread::PostTask(
48 BrowserThread::UI, FROM_HERE,
49 base::Bind(&SysteminfoStorageGetFunction::RespondOnUIThread,
50 this, success));
51 }
52
53 void SysteminfoStorageGetFunction::RespondOnUIThread(bool success) {
54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
55 SendResponse(success);
56 }
57
58 #if !defined(OS_WIN)
59 // A Mock implementation for temporary usage. Will be moved out for testing
60 // once the platform specifc implementations are ready.
61 const char kStorageTypeUnknownStr[] = "unknown";
Mihai Parparita -not on Chrome 2012/08/10 20:46:47 BTW, filed http://crbug.com/141940, which, if fixe
62 const char kStorageTypeHardDiskStr[] = "harddisk";
63 const char kStorageTypeUSBStr[] = "usb";
64 const char kStorageTypeMMCStr[] = "mmc";
65
66 class MockStorageInfoProvider : public StorageInfoProvider {
67 public:
68 MockStorageInfoProvider() {}
69 virtual ~MockStorageInfoProvider() {}
70 virtual bool GetStorageInfo(StorageInfo* info) OVERRIDE;
71 };
72
73 bool MockStorageInfoProvider::GetStorageInfo(StorageInfo* info) {
74 if (info == NULL) return false;
75 linked_ptr<StorageUnitInfo> unit(new StorageUnitInfo());
76 unit->id = "0xbeaf";
77 unit->type = kStorageTypeUnknownStr;
78 unit->capacity = 4098;
79 unit->available_capacity = 1000;
80
81 info->units.push_back(unit);
82 return true;
83 }
84
85 // static
86 StorageInfoProvider* StorageInfoProvider::Create() {
87 return new MockStorageInfoProvider();
88 }
89 #endif // !OS_WIN
90
91 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698