Chromium Code Reviews| Index: chrome/browser/extensions/api/systeminfo_storage/systeminfo_storage_api.cc |
| diff --git a/chrome/browser/extensions/api/systeminfo_storage/systeminfo_storage_api.cc b/chrome/browser/extensions/api/systeminfo_storage/systeminfo_storage_api.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d092e76c67c9fc3fa2f0435c8f743ab60fc80781 |
| --- /dev/null |
| +++ b/chrome/browser/extensions/api/systeminfo_storage/systeminfo_storage_api.cc |
| @@ -0,0 +1,57 @@ |
| +// 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. |
| +#include "chrome/browser/extensions/api/systeminfo_storage/systeminfo_storage_api.h" |
| + |
| +#include "base/logging.h" |
| +#include "base/json/json_writer.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/string_number_conversions.h" |
| +#include "base/string_piece.h" |
| +#include "base/values.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "chrome/browser/extensions/extension_service.h" |
| +#include "chrome/browser/extensions/api/systeminfo_storage/storage_info_provider.h" |
| + |
| +namespace extensions { |
| +using content::BrowserThread; |
| + |
| +SysteminfoStorageGetFunction::SysteminfoStorageGetFunction() { |
| +} |
| + |
| +SysteminfoStorageGetFunction::~SysteminfoStorageGetFunction() { |
| +} |
| + |
| +bool SysteminfoStorageGetFunction::RunImpl() { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| + base::Bind(&SysteminfoStorageGetFunction::WorkOnFileThread, this)); |
|
James Hawkins
2012/08/09 15:47:34
nit: Start of parameter rows must align on the sam
Hongbo Min
2012/08/12 03:31:58
Done.
|
| + return true; |
| +} |
| + |
| +void SysteminfoStorageGetFunction::WorkOnFileThread() { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| + bool success = false; |
| + scoped_ptr<StorageInfoProvider> provider(StorageInfoProvider::Create()); |
| + StorageInfo info; |
| + if (provider.get() && provider->GetStorageInfo(&info)) { |
|
James Hawkins
2012/08/09 15:47:34
Why would provider.get() ever be non-NULL?
Hongbo Min
2012/08/10 02:43:29
In case of out of memory, the allocation for provi
James Hawkins
2012/08/11 16:37:54
Chrome code does not check for OOM situations, so
|
| + SetResult(info.ToValue().release()); |
| + success = true; |
| + } else { |
| + SetError("Error in querying storage information"); |
| + success = false; |
|
James Hawkins
2012/08/09 15:47:34
nit: This line is redundant with line 34.
Hongbo Min
2012/08/12 03:31:58
Done.
|
| + } |
| + |
| + // Response on UI thread |
|
James Hawkins
2012/08/09 15:47:34
nit: Comments must end with a period.
Hongbo Min
2012/08/12 03:31:58
Done.
|
| + BrowserThread::PostTask( |
| + BrowserThread::UI, FROM_HERE, |
| + base::Bind(&SysteminfoStorageGetFunction::RespondOnUIThread, |
|
James Hawkins
2012/08/09 15:47:34
nit: Alignment is off.
Hongbo Min
2012/08/12 03:31:58
Done.
|
| + this, success)); |
| +} |
| + |
| +void SysteminfoStorageGetFunction::RespondOnUIThread(bool success) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + SendResponse(success); |
| +} |
| + |
| +} // namespace extensions |