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

Unified Diff: chrome/browser/extensions/api/cloud_print_private/cloud_print_private_api.cc

Issue 12769009: Pass list of printers to chrome using file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/common/chrome_switches.h » ('j') | chrome/common/chrome_switches.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/api/cloud_print_private/cloud_print_private_api.cc
diff --git a/chrome/browser/extensions/api/cloud_print_private/cloud_print_private_api.cc b/chrome/browser/extensions/api/cloud_print_private/cloud_print_private_api.cc
index 37ca794d1e530ac666202d5398cdf56041f1ea9c..3a3d4676eb6a77681be3ac63b402268ca06c5cfb 100644
--- a/chrome/browser/extensions/api/cloud_print_private/cloud_print_private_api.cc
+++ b/chrome/browser/extensions/api/cloud_print_private/cloud_print_private_api.cc
@@ -6,9 +6,13 @@
#include <string>
+#include "base/command_line.h"
+#include "base/file_util.h"
+#include "base/json/json_reader.h"
#include "base/threading/sequenced_worker_pool.h"
#include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h"
#include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory.h"
+#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/api/cloud_print_private.h"
#include "google_apis/google_api_keys.h"
#include "net/base/net_util.h"
@@ -91,20 +95,38 @@ void CloudPrintPrivateGetPrintersFunction::ReturnResult(
}
void CloudPrintPrivateGetPrintersFunction::CollectPrinters() {
- scoped_ptr<base::ListValue> result(new base::ListValue());
- if (CloudPrintTestsDelegate::instance()) {
- std::vector<std::string> printers =
- CloudPrintTestsDelegate::instance()->GetPrinters();
- for (size_t i = 0; i < printers.size(); ++i)
- result->Append(Value::CreateStringValue(printers[i]));
+ scoped_ptr<base::ListValue> result;
+
+ CommandLine* command_line = CommandLine::ForCurrentProcess();
+ base::FilePath list_path(
+ command_line->GetSwitchValuePath(switches::kCloudPrintAddPrinters));
+ if (!list_path.empty()) {
+ std::string printers_json;
+ file_util::ReadFileToString(list_path, &printers_json);
+ scoped_ptr<Value> value(base::JSONReader::Read(printers_json));
+ base::ListValue* list = NULL;
+ if (value)
+ value->GetAsList(&list);
+ if (list) {
+ result.reset(list);
+ value.release(); // Holds the same object as result.
+ }
} else {
- printing::PrinterList printers;
- scoped_refptr<printing::PrintBackend> backend(
- printing::PrintBackend::CreateInstance(NULL));
- if (backend)
- backend->EnumeratePrinters(&printers);
- for (size_t i = 0; i < printers.size(); ++i)
- result->Append(Value::CreateStringValue(printers[i].printer_name));
+ result.reset(new base::ListValue());
+ if (CloudPrintTestsDelegate::instance()) {
+ std::vector<std::string> printers =
+ CloudPrintTestsDelegate::instance()->GetPrinters();
+ for (size_t i = 0; i < printers.size(); ++i)
+ result->Append(Value::CreateStringValue(printers[i]));
+ } else {
+ printing::PrinterList printers;
+ scoped_refptr<printing::PrintBackend> backend(
+ printing::PrintBackend::CreateInstance(NULL));
+ if (backend)
+ backend->EnumeratePrinters(&printers);
+ for (size_t i = 0; i < printers.size(); ++i)
+ result->Append(Value::CreateStringValue(printers[i].printer_name));
+ }
}
content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
base::Bind(&CloudPrintPrivateGetPrintersFunction::ReturnResult, this,
« no previous file with comments | « no previous file | chrome/common/chrome_switches.h » ('j') | chrome/common/chrome_switches.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698