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 } | 68 } |
69 | 69 |
70 if (state.cdd.get()) | 70 if (state.cdd.get()) |
71 json.Set(kCdd, state.cdd->DeepCopy()); | 71 json.Set(kCdd, state.cdd->DeepCopy()); |
72 | 72 |
73 std::string json_str; | 73 std::string json_str; |
74 base::JSONWriter::WriteWithOptions(&json, | 74 base::JSONWriter::WriteWithOptions(&json, |
75 base::JSONWriter::OPTIONS_PRETTY_PRINT, | 75 base::JSONWriter::OPTIONS_PRETTY_PRINT, |
76 &json_str); | 76 &json_str); |
77 int size = base::checked_cast<int>(json_str.size()); | 77 int size = base::checked_cast<int>(json_str.size()); |
78 return (file_util::WriteFile(path, json_str.data(), size) == size); | 78 return (base::WriteFile(path, json_str.data(), size) == size); |
79 } | 79 } |
80 | 80 |
81 bool LoadFromFile(const base::FilePath& path, PrinterState* state) { | 81 bool LoadFromFile(const base::FilePath& path, PrinterState* state) { |
82 std::string json_str; | 82 std::string json_str; |
83 if (!base::ReadFileToString(path, &json_str)) { | 83 if (!base::ReadFileToString(path, &json_str)) { |
84 LOG(ERROR) << "Cannot open file."; | 84 LOG(ERROR) << "Cannot open file."; |
85 return false; | 85 return false; |
86 } | 86 } |
87 | 87 |
88 scoped_ptr<base::Value> json_val(base::JSONReader::Read(json_str)); | 88 scoped_ptr<base::Value> json_val(base::JSONReader::Read(json_str)); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 state->access_token = access_token; | 168 state->access_token = access_token; |
169 state->access_token_update = base::Time::FromTimeT(access_token_update); | 169 state->access_token_update = base::Time::FromTimeT(access_token_update); |
170 state->local_settings = local_settings; | 170 state->local_settings = local_settings; |
171 if (cdd_dict) | 171 if (cdd_dict) |
172 state->cdd.reset(cdd_dict->DeepCopy()); | 172 state->cdd.reset(cdd_dict->DeepCopy()); |
173 return true; | 173 return true; |
174 } | 174 } |
175 | 175 |
176 } // namespace printer_state | 176 } // namespace printer_state |
177 | 177 |
OLD | NEW |