| 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/json/json_string_value_serializer.h" | 11 #include "base/json/json_string_value_serializer.h" |
| 12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
| 13 #include "base/metrics/user_metrics.h" | 13 #include "base/metrics/user_metrics.h" |
| 14 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
| 15 #include "base/strings/string_piece.h" |
| 15 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/chrome_notification_types.h" | 17 #include "chrome/browser/chrome_notification_types.h" |
| 17 #include "chrome/browser/google/google_profile_helper.h" | 18 #include "chrome/browser/google/google_profile_helper.h" |
| 18 #include "chrome/browser/media/media_stream_infobar_delegate.h" | 19 #include "chrome/browser/media/media_stream_infobar_delegate.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/search/hotword_service.h" | 21 #include "chrome/browser/search/hotword_service.h" |
| 21 #include "chrome/browser/search/hotword_service_factory.h" | 22 #include "chrome/browser/search/hotword_service_factory.h" |
| 22 #include "chrome/browser/ui/app_list/speech_auth_helper.h" | 23 #include "chrome/browser/ui/app_list/speech_auth_helper.h" |
| 23 #include "chrome/browser/ui/app_list/speech_recognizer.h" | 24 #include "chrome/browser/ui/app_list/speech_recognizer.h" |
| 24 #include "chrome/browser/ui/app_list/start_page_observer.h" | 25 #include "chrome/browser/ui/app_list/start_page_observer.h" |
| (...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 doodle_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES); | 534 doodle_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES); |
| 534 doodle_fetcher_->Start(); | 535 doodle_fetcher_->Start(); |
| 535 } | 536 } |
| 536 | 537 |
| 537 void StartPageService::OnURLFetchComplete(const net::URLFetcher* source) { | 538 void StartPageService::OnURLFetchComplete(const net::URLFetcher* source) { |
| 538 std::string json_data; | 539 std::string json_data; |
| 539 source->GetResponseAsString(&json_data); | 540 source->GetResponseAsString(&json_data); |
| 540 | 541 |
| 541 // Remove XSSI guard for JSON parsing. | 542 // Remove XSSI guard for JSON parsing. |
| 542 size_t json_start_index = json_data.find("{"); | 543 size_t json_start_index = json_data.find("{"); |
| 544 base::StringPiece json_data_substr(json_data); |
| 543 if (json_start_index != std::string::npos) | 545 if (json_start_index != std::string::npos) |
| 544 json_data.erase(0, json_start_index); | 546 json_data_substr.remove_prefix(json_start_index); |
| 545 | 547 |
| 546 JSONStringValueSerializer deserializer(json_data); | 548 JSONStringValueSerializer deserializer(json_data_substr); |
| 547 deserializer.set_allow_trailing_comma(true); | 549 deserializer.set_allow_trailing_comma(true); |
| 548 int error_code = 0; | 550 int error_code = 0; |
| 549 scoped_ptr<base::Value> doodle_json( | 551 scoped_ptr<base::Value> doodle_json( |
| 550 deserializer.Deserialize(&error_code, nullptr)); | 552 deserializer.Deserialize(&error_code, nullptr)); |
| 551 | 553 |
| 552 base::TimeDelta recheck_delay = | 554 base::TimeDelta recheck_delay = |
| 553 base::TimeDelta::FromMinutes(kDefaultDoodleRecheckDelayMinutes); | 555 base::TimeDelta::FromMinutes(kDefaultDoodleRecheckDelayMinutes); |
| 554 | 556 |
| 555 if (error_code == 0) { | 557 if (error_code == 0) { |
| 556 base::DictionaryValue* doodle_dictionary = nullptr; | 558 base::DictionaryValue* doodle_dictionary = nullptr; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 570 | 572 |
| 571 // Check for a new doodle. | 573 // Check for a new doodle. |
| 572 content::BrowserThread::PostDelayedTask( | 574 content::BrowserThread::PostDelayedTask( |
| 573 content::BrowserThread::UI, FROM_HERE, | 575 content::BrowserThread::UI, FROM_HERE, |
| 574 base::Bind(&StartPageService::FetchDoodleJson, | 576 base::Bind(&StartPageService::FetchDoodleJson, |
| 575 weak_factory_.GetWeakPtr()), | 577 weak_factory_.GetWeakPtr()), |
| 576 recheck_delay); | 578 recheck_delay); |
| 577 } | 579 } |
| 578 | 580 |
| 579 } // namespace app_list | 581 } // namespace app_list |
| OLD | NEW |