File: composebox_query_controller_ios.mm

package info (click to toggle)
chromium 141.0.7390.122-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,246,384 kB
  • sloc: cpp: 35,265,044; ansic: 7,169,920; javascript: 4,250,185; python: 1,460,635; asm: 950,788; xml: 751,771; pascal: 187,972; sh: 89,459; perl: 88,691; objc: 79,953; sql: 53,924; cs: 44,622; fortran: 24,137; makefile: 22,313; tcl: 15,277; php: 14,018; yacc: 8,995; ruby: 7,553; awk: 3,720; lisp: 3,096; lex: 1,330; ada: 727; jsp: 228; sed: 36
file content (53 lines) | stat: -rw-r--r-- 2,085 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import "components/omnibox/composebox/ios/composebox_query_controller_ios.h"

#import <UIKit/UIKit.h>

#include <optional>
#include <vector>

#import "base/task/bind_post_task.h"
#import "base/task/thread_pool.h"
#import "components/lens/lens_bitmap_processing.h"
#import "components/lens/ref_counted_lens_overlay_client_logs.h"
#import "components/omnibox/composebox/ios/composebox_image_helper_ios.h"
#import "third_party/lens_server_proto/lens_overlay_server.pb.h"

void ComposeboxQueryControllerIOS::CreateImageUploadRequest(
    const base::UnguessableToken& file_token,
    const std::vector<uint8_t>& image_data,
    std::optional<lens::ImageEncodingOptions> image_options,
    RequestBodyProtoCreatedCallback callback) {
  FileInfo* file_info = GetFileInfo(file_token);
  if (!file_info) {
    return;
  }

  CHECK(image_options.has_value());
  // On iOS, we use UIImage for decoding and resizing.
  NSData* image_ns_data = [NSData dataWithBytes:image_data.data()
                                         length:image_data.size()];
  UIImage* image = [UIImage imageWithData:image_ns_data];

  if (!image) {
    std::move(callback).Run(lens::LensOverlayServerRequest(),
                            FileUploadErrorType::kImageProcessingError);
    return;
  }

  scoped_refptr<lens::RefCountedLensOverlayClientLogs> ref_counted_logs =
      base::MakeRefCounted<lens::RefCountedLensOverlayClientLogs>();

  // Downscaling and encoding is done on a background thread.
  create_request_task_runner_->PostTaskAndReplyWithResult(
      FROM_HERE,
      base::BindOnce(&composebox::DownscaleAndEncodeImage, image,
                     ref_counted_logs, image_options.value()),
      base::BindOnce(&ComposeboxQueryController::
                         CreateFileUploadRequestProtoWithImageDataAndContinue,
                     *file_info->request_id_, CreateClientContext(),
                     ref_counted_logs, std::move(callback)));
}