OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cloud_print/gcp20/prototype/printer_state.h" | 5 #include "cloud_print/gcp20/prototype/printer_state.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 std::string json_str; | 68 std::string json_str; |
69 base::JSONWriter::WriteWithOptions(&json, | 69 base::JSONWriter::WriteWithOptions(&json, |
70 base::JSONWriter::OPTIONS_PRETTY_PRINT, | 70 base::JSONWriter::OPTIONS_PRETTY_PRINT, |
71 &json_str); | 71 &json_str); |
72 return !!file_util::WriteFile(path, json_str.data(), | 72 return !!file_util::WriteFile(path, json_str.data(), |
73 static_cast<int>(json_str.size())); | 73 static_cast<int>(json_str.size())); |
74 } | 74 } |
75 | 75 |
76 bool LoadFromFile(const base::FilePath& path, PrinterState* state) { | 76 bool LoadFromFile(const base::FilePath& path, PrinterState* state) { |
77 std::string json_str; | 77 std::string json_str; |
78 if (!file_util::ReadFileToString(path, &json_str)) { | 78 if (!base::ReadFileToString(path, &json_str)) { |
79 LOG(ERROR) << "Cannot open file."; | 79 LOG(ERROR) << "Cannot open file."; |
80 return false; | 80 return false; |
81 } | 81 } |
82 | 82 |
83 scoped_ptr<base::Value> json_val(base::JSONReader::Read(json_str)); | 83 scoped_ptr<base::Value> json_val(base::JSONReader::Read(json_str)); |
84 base::DictionaryValue* json = NULL; | 84 base::DictionaryValue* json = NULL; |
85 if (!json_val || !json_val->GetAsDictionary(&json)) { | 85 if (!json_val || !json_val->GetAsDictionary(&json)) { |
86 LOG(ERROR) << "Cannot read JSON dictionary from file."; | 86 LOG(ERROR) << "Cannot read JSON dictionary from file."; |
87 return false; | 87 return false; |
88 } | 88 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 state->refresh_token = refresh_token; | 157 state->refresh_token = refresh_token; |
158 state->xmpp_jid = xmpp_jid; | 158 state->xmpp_jid = xmpp_jid; |
159 state->access_token = access_token; | 159 state->access_token = access_token; |
160 state->access_token_update = base::Time::FromTimeT(access_token_update); | 160 state->access_token_update = base::Time::FromTimeT(access_token_update); |
161 state->local_settings = local_settings; | 161 state->local_settings = local_settings; |
162 return true; | 162 return true; |
163 } | 163 } |
164 | 164 |
165 } // namespace printer_state | 165 } // namespace printer_state |
166 | 166 |
OLD | NEW |