| 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" |
| (...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 | 660 |
| 661 // Remove XSSI guard for JSON parsing. | 661 // Remove XSSI guard for JSON parsing. |
| 662 size_t json_start_index = json_data.find("{"); | 662 size_t json_start_index = json_data.find("{"); |
| 663 base::StringPiece json_data_substr(json_data); | 663 base::StringPiece json_data_substr(json_data); |
| 664 if (json_start_index != std::string::npos) | 664 if (json_start_index != std::string::npos) |
| 665 json_data_substr.remove_prefix(json_start_index); | 665 json_data_substr.remove_prefix(json_start_index); |
| 666 | 666 |
| 667 JSONStringValueDeserializer deserializer(json_data_substr); | 667 JSONStringValueDeserializer deserializer(json_data_substr); |
| 668 deserializer.set_allow_trailing_comma(true); | 668 deserializer.set_allow_trailing_comma(true); |
| 669 int error_code = 0; | 669 int error_code = 0; |
| 670 scoped_ptr<base::Value> doodle_json( | 670 scoped_ptr<base::Value> doodle_json = |
| 671 deserializer.Deserialize(&error_code, nullptr)); | 671 deserializer.Deserialize(&error_code, nullptr); |
| 672 | 672 |
| 673 base::TimeDelta recheck_delay; | 673 base::TimeDelta recheck_delay; |
| 674 if (error_code != 0) { | 674 if (error_code != 0) { |
| 675 // On failure, use expotential backoff. | 675 // On failure, use expotential backoff. |
| 676 backoff_entry_.InformOfRequest(false); | 676 backoff_entry_.InformOfRequest(false); |
| 677 recheck_delay = backoff_entry_.GetTimeUntilRelease(); | 677 recheck_delay = backoff_entry_.GetTimeUntilRelease(); |
| 678 } else { | 678 } else { |
| 679 // If we received information, even if there's no doodle, reset the backoff | 679 // If we received information, even if there's no doodle, reset the backoff |
| 680 // entry and start rechecking for the doodle at the maximum interval. | 680 // entry and start rechecking for the doodle at the maximum interval. |
| 681 backoff_entry_.Reset(); | 681 backoff_entry_.Reset(); |
| 682 recheck_delay = base::TimeDelta::FromMilliseconds(kMaximumRecheckDelayMs); | 682 recheck_delay = base::TimeDelta::FromMilliseconds(kMaximumRecheckDelayMs); |
| 683 | 683 |
| 684 if (contents_ && contents_->GetWebUI()) { | 684 if (contents_ && contents_->GetWebUI()) { |
| 685 contents_->GetWebUI()->CallJavascriptFunction( | 685 contents_->GetWebUI()->CallJavascriptFunction( |
| 686 "appList.startPage.onAppListDoodleUpdated", *doodle_json, | 686 "appList.startPage.onAppListDoodleUpdated", *doodle_json, |
| 687 base::StringValue( | 687 base::StringValue( |
| 688 UIThreadSearchTermsData(profile_).GoogleBaseURLValue())); | 688 UIThreadSearchTermsData(profile_).GoogleBaseURLValue())); |
| 689 } | 689 } |
| 690 } | 690 } |
| 691 | 691 |
| 692 // Check for a new doodle. | 692 // Check for a new doodle. |
| 693 content::BrowserThread::PostDelayedTask( | 693 content::BrowserThread::PostDelayedTask( |
| 694 content::BrowserThread::UI, FROM_HERE, | 694 content::BrowserThread::UI, FROM_HERE, |
| 695 base::Bind(&StartPageService::FetchDoodleJson, | 695 base::Bind(&StartPageService::FetchDoodleJson, |
| 696 weak_factory_.GetWeakPtr()), | 696 weak_factory_.GetWeakPtr()), |
| 697 recheck_delay); | 697 recheck_delay); |
| 698 } | 698 } |
| 699 | 699 |
| 700 } // namespace app_list | 700 } // namespace app_list |
| OLD | NEW |