Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Side by Side Diff: chrome/browser/android/offline_pages/offline_page_bridge.cc

Issue 2007113007: Offline Pages: Add NULL-checks for when the model is NULL (incognito mode) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2743
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/android/offline_pages/offline_page_bridge.h" 5 #include "chrome/browser/android/offline_pages/offline_page_bridge.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/android/jni_array.h" 10 #include "base/android/jni_array.h"
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 const JavaParamRef<jstring>& j_url) { 154 const JavaParamRef<jstring>& j_url) {
155 GURL url(ConvertJavaStringToUTF8(env, j_url)); 155 GURL url(ConvertJavaStringToUTF8(env, j_url));
156 return url.is_valid() && OfflinePageModel::CanSavePage(url); 156 return url.is_valid() && OfflinePageModel::CanSavePage(url);
157 } 157 }
158 158
159 static ScopedJavaLocalRef<jobject> GetOfflinePageBridgeForProfile( 159 static ScopedJavaLocalRef<jobject> GetOfflinePageBridgeForProfile(
160 JNIEnv* env, 160 JNIEnv* env,
161 const JavaParamRef<jclass>& jcaller, 161 const JavaParamRef<jclass>& jcaller,
162 const JavaParamRef<jobject>& j_profile) { 162 const JavaParamRef<jobject>& j_profile) {
163 Profile* profile = ProfileAndroid::FromProfileAndroid(j_profile); 163 Profile* profile = ProfileAndroid::FromProfileAndroid(j_profile);
164
164 OfflinePageModel* offline_page_model = 165 OfflinePageModel* offline_page_model =
165 OfflinePageModelFactory::GetForBrowserContext(profile); 166 OfflinePageModelFactory::GetForBrowserContext(profile);
166 167
168 if (offline_page_model == nullptr)
169 return ScopedJavaLocalRef<jobject>();
170
167 OfflinePageBridge* bridge = static_cast<OfflinePageBridge*>( 171 OfflinePageBridge* bridge = static_cast<OfflinePageBridge*>(
168 offline_page_model->GetUserData(kOfflinePageBridgeKey)); 172 offline_page_model->GetUserData(kOfflinePageBridgeKey));
169 if (!bridge) { 173 if (!bridge) {
170 bridge = new OfflinePageBridge(env, profile, offline_page_model); 174 bridge = new OfflinePageBridge(env, profile, offline_page_model);
171 offline_page_model->SetUserData(kOfflinePageBridgeKey, bridge); 175 offline_page_model->SetUserData(kOfflinePageBridgeKey, bridge);
172 } 176 }
177
173 return ScopedJavaLocalRef<jobject>(bridge->java_ref()); 178 return ScopedJavaLocalRef<jobject>(bridge->java_ref());
174 } 179 }
175 180
176 OfflinePageBridge::OfflinePageBridge(JNIEnv* env, 181 OfflinePageBridge::OfflinePageBridge(JNIEnv* env,
177 content::BrowserContext* browser_context, 182 content::BrowserContext* browser_context,
178 OfflinePageModel* offline_page_model) 183 OfflinePageModel* offline_page_model)
179 : browser_context_(browser_context), 184 : browser_context_(browser_context),
180 offline_page_model_(offline_page_model) { 185 offline_page_model_(offline_page_model) {
181 ScopedJavaLocalRef<jobject> j_offline_page_bridge = 186 ScopedJavaLocalRef<jobject> j_offline_page_bridge =
182 Java_OfflinePageBridge_create(env, reinterpret_cast<jlong>(this)); 187 Java_OfflinePageBridge_create(env, reinterpret_cast<jlong>(this));
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 ConvertUTF8ToJavaString(env, client_id.name_space).obj(), 412 ConvertUTF8ToJavaString(env, client_id.name_space).obj(),
408 ConvertUTF8ToJavaString(env, client_id.id).obj()); 413 ConvertUTF8ToJavaString(env, client_id.id).obj());
409 } 414 }
410 415
411 bool RegisterOfflinePageBridge(JNIEnv* env) { 416 bool RegisterOfflinePageBridge(JNIEnv* env) {
412 return RegisterNativesImpl(env); 417 return RegisterNativesImpl(env);
413 } 418 }
414 419
415 } // namespace android 420 } // namespace android
416 } // namespace offline_pages 421 } // namespace offline_pages
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698