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 "chrome/browser/ui/app_list/start_page_service.h" | 5 #include "chrome/browser/ui/app_list/start_page_service.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/json/json_reader.h" |
13 #include "base/json/json_string_value_serializer.h" | 14 #include "base/json/json_string_value_serializer.h" |
14 #include "base/macros.h" | 15 #include "base/macros.h" |
15 #include "base/memory/singleton.h" | 16 #include "base/memory/singleton.h" |
16 #include "base/metrics/user_metrics.h" | 17 #include "base/metrics/user_metrics.h" |
17 #include "base/strings/string_piece.h" | 18 #include "base/strings/string_piece.h" |
18 #include "build/build_config.h" | 19 #include "build/build_config.h" |
19 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
20 #include "chrome/browser/chrome_notification_types.h" | 21 #include "chrome/browser/chrome_notification_types.h" |
21 #include "chrome/browser/media/webrtc/media_stream_devices_controller.h" | 22 #include "chrome/browser/media/webrtc/media_stream_devices_controller.h" |
22 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
649 void StartPageService::OnURLFetchComplete(const net::URLFetcher* source) { | 650 void StartPageService::OnURLFetchComplete(const net::URLFetcher* source) { |
650 std::string json_data; | 651 std::string json_data; |
651 source->GetResponseAsString(&json_data); | 652 source->GetResponseAsString(&json_data); |
652 | 653 |
653 // Remove XSSI guard for JSON parsing. | 654 // Remove XSSI guard for JSON parsing. |
654 size_t json_start_index = json_data.find("{"); | 655 size_t json_start_index = json_data.find("{"); |
655 base::StringPiece json_data_substr(json_data); | 656 base::StringPiece json_data_substr(json_data); |
656 if (json_start_index != std::string::npos) | 657 if (json_start_index != std::string::npos) |
657 json_data_substr.remove_prefix(json_start_index); | 658 json_data_substr.remove_prefix(json_start_index); |
658 | 659 |
659 JSONStringValueDeserializer deserializer(json_data_substr); | 660 JSONStringValueDeserializer deserializer(json_data_substr, |
660 deserializer.set_allow_trailing_comma(true); | 661 base::JSON_ALLOW_TRAILING_COMMAS); |
661 int error_code = 0; | 662 int error_code = 0; |
662 std::unique_ptr<base::Value> doodle_json = | 663 std::unique_ptr<base::Value> doodle_json = |
663 deserializer.Deserialize(&error_code, nullptr); | 664 deserializer.Deserialize(&error_code, nullptr); |
664 | 665 |
665 base::TimeDelta recheck_delay; | 666 base::TimeDelta recheck_delay; |
666 if (error_code != 0) { | 667 if (error_code != 0) { |
667 // On failure, use expotential backoff. | 668 // On failure, use expotential backoff. |
668 backoff_entry_.InformOfRequest(false); | 669 backoff_entry_.InformOfRequest(false); |
669 recheck_delay = backoff_entry_.GetTimeUntilRelease(); | 670 recheck_delay = backoff_entry_.GetTimeUntilRelease(); |
670 } else { | 671 } else { |
(...skipping 12 matching lines...) Expand all Loading... |
683 | 684 |
684 // Check for a new doodle. | 685 // Check for a new doodle. |
685 content::BrowserThread::PostDelayedTask( | 686 content::BrowserThread::PostDelayedTask( |
686 content::BrowserThread::UI, FROM_HERE, | 687 content::BrowserThread::UI, FROM_HERE, |
687 base::Bind(&StartPageService::FetchDoodleJson, | 688 base::Bind(&StartPageService::FetchDoodleJson, |
688 weak_factory_.GetWeakPtr()), | 689 weak_factory_.GetWeakPtr()), |
689 recheck_delay); | 690 recheck_delay); |
690 } | 691 } |
691 | 692 |
692 } // namespace app_list | 693 } // namespace app_list |
OLD | NEW |