| OLD | NEW | 
|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/web_resource/web_resource_service.h" | 5 #include "chrome/browser/web_resource/web_resource_service.h" | 
| 6 | 6 | 
| 7 #include "base/bind.h" | 7 #include "base/bind.h" | 
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" | 
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" | 
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" | 
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 86         delay = ms_until_update; | 86         delay = ms_until_update; | 
| 87     } | 87     } | 
| 88   } | 88   } | 
| 89   // Start fetch and wait for UpdateResourceCache. | 89   // Start fetch and wait for UpdateResourceCache. | 
| 90   ScheduleFetch(delay); | 90   ScheduleFetch(delay); | 
| 91 } | 91 } | 
| 92 | 92 | 
| 93 // Delay initial load of resource data into cache so as not to interfere | 93 // Delay initial load of resource data into cache so as not to interfere | 
| 94 // with startup time. | 94 // with startup time. | 
| 95 void WebResourceService::ScheduleFetch(int64 delay_ms) { | 95 void WebResourceService::ScheduleFetch(int64 delay_ms) { | 
| 96   MessageLoop::current()->PostDelayedTask( | 96   base::MessageLoop::current()->PostDelayedTask( | 
| 97       FROM_HERE, | 97       FROM_HERE, | 
| 98       base::Bind(&WebResourceService::StartFetch, | 98       base::Bind(&WebResourceService::StartFetch, | 
| 99                  weak_ptr_factory_.GetWeakPtr()), | 99                  weak_ptr_factory_.GetWeakPtr()), | 
| 100       base::TimeDelta::FromMilliseconds(delay_ms)); | 100       base::TimeDelta::FromMilliseconds(delay_ms)); | 
| 101 } | 101 } | 
| 102 | 102 | 
| 103 // Initializes the fetching of data from the resource server.  Data | 103 // Initializes the fetching of data from the resource server.  Data | 
| 104 // load calls OnURLFetchComplete. | 104 // load calls OnURLFetchComplete. | 
| 105 void WebResourceService::StartFetch() { | 105 void WebResourceService::StartFetch() { | 
| 106   // First, put our next cache load on the MessageLoop. | 106   // First, put our next cache load on the MessageLoop. | 
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 149     json_unpacker_->Start(data); | 149     json_unpacker_->Start(data); | 
| 150   } else { | 150   } else { | 
| 151     // Don't parse data if attempt to download was unsuccessful. | 151     // Don't parse data if attempt to download was unsuccessful. | 
| 152     // Stop loading new web resource data, and silently exit. | 152     // Stop loading new web resource data, and silently exit. | 
| 153     // We do not call UnpackerClient, so we need to call EndFetch ourselves. | 153     // We do not call UnpackerClient, so we need to call EndFetch ourselves. | 
| 154     EndFetch(); | 154     EndFetch(); | 
| 155   } | 155   } | 
| 156 | 156 | 
| 157   Release(); | 157   Release(); | 
| 158 } | 158 } | 
| OLD | NEW | 
|---|